Skip to content

Commit 3537eb9

Browse files
authoredMar 13, 2025
Handle malformed baseType data with extraneous whitespace. (#921)
Resolves: rdar://139449414
1 parent 3559f01 commit 3537eb9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
 

‎src/components/DocumentationTopic/PrimaryContent/PropertyListKeyType.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
},
2424
computed: {
2525
englishTypes() {
26-
return this.types.map(({
26+
return this.sanitizedTypes.map(({
2727
arrayMode,
2828
baseType = '*',
2929
}) => (arrayMode ? (
@@ -32,6 +32,7 @@ export default {
3232
baseType
3333
)));
3434
},
35+
sanitizedTypes: ({ sanitizeType, types }) => types.map(sanitizeType),
3536
typeOutput() {
3637
if (this.englishTypes.length > 2) {
3738
return [this.englishTypes.slice(0, this.englishTypes.length - 1).join(', '),
@@ -54,6 +55,14 @@ export default {
5455
return type;
5556
}
5657
},
58+
// trim extra starting/end whitespace of baseType strings in case they
59+
// unexpectedly come through that way in the JSON
60+
sanitizeType(type) {
61+
const { baseType } = type;
62+
return baseType
63+
? { ...type, baseType: baseType.trim() }
64+
: type;
65+
},
5766
},
5867
};
5968
</script>

‎tests/unit/components/DocumentationTopic/PrimaryContent/PropertyListKeyType.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ describe('PropertyListKeyType', () => {
6060
{ arrayMode: true },
6161
]).text()).toBe('* or array of *');
6262
});
63+
64+
it('handles extraneous whitespace when pluralizing types', () => {
65+
expect(mountWithTypes([
66+
{
67+
baseType: 'dictionary ',
68+
arrayMode: true,
69+
},
70+
]).text()).toBe('array of dictionaries');
71+
});
6372
});

0 commit comments

Comments
 (0)