Skip to content

Commit 9fe7d4f

Browse files
akolsonclaude
andcommitted
Fix TypeError when languageText called with non-language object
VAutocomplete eagerly evaluates getText(internalValue) as the fallback argument to getValue, even when the fallback is never used. In multiple mode (used in SearchFilters), internalValue is an Array of selected ids. Arrays are objects in JS, so getPropertyFromItem does not short-circuit on the primitive guard and calls languageText with the array directly. Since arrays have no native_name property, this throws a TypeError. Guard languageText against item being null/undefined or lacking a native_name (covers arrays, partial objects, and any future edge cases). Fixes #5740. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c2f2777 commit 9fe7d4f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

contentcuration/contentcuration/frontend/shared/views/LanguageDropdown.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@
113113
},
114114
methods: {
115115
languageText(item) {
116+
// VAutocomplete eagerly evaluates getText(internalValue) as a fallback arg to
117+
// getValue, even when that fallback isn't needed. In multiple mode, internalValue
118+
// is an Array, and arrays have no native_name. Guard against both that case and
119+
// any other scenario where item or native_name is missing.
120+
if (!item || item.native_name == null) {
121+
return '';
122+
}
116123
const firstNativeName = item.native_name.split(',')[0].trim();
117124
return this.$tr('languageItemText', { language: firstNativeName, code: item.id });
118125
},

contentcuration/contentcuration/frontend/shared/views/__tests__/languageDropdown.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,25 @@ describe('languageDropdown', () => {
8181
const item = { native_name: '', id: 'de' };
8282
expect(wrapper.vm.languageText(item)).toBe(' (de)');
8383
});
84+
85+
it('returns empty string when native_name is missing', () => {
86+
const wrapper = shallowMount(LanguageDropdown, {
87+
mocks: {
88+
$tr: (key, params) => `${params.language} (${params.code})`,
89+
},
90+
});
91+
const item = { id: 'fr' };
92+
expect(wrapper.vm.languageText(item)).toBe('');
93+
});
94+
95+
it('returns empty string when called with an array (multiple mode VAutocomplete internal call)', () => {
96+
const wrapper = shallowMount(LanguageDropdown, {
97+
mocks: {
98+
$tr: (key, params) => `${params.language} (${params.code})`,
99+
},
100+
});
101+
// VAutocomplete eagerly evaluates getText(internalValue) as a fallback to getValue.
102+
// In multiple mode, internalValue is an Array, so languageText receives the array.
103+
expect(wrapper.vm.languageText(['en', 'fr'])).toBe('');
104+
});
84105
});

0 commit comments

Comments
 (0)