Skip to content

Commit 76e9486

Browse files
authored
fix: md names handle spaces, colons, and both (#1297)
1 parent 6acc12e commit 76e9486

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/collections/componentSetBuilder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,16 @@ export const entryToTypeAndName =
297297
(reg: RegistryAccess) =>
298298
(rawEntry: string): MetadataTypeAndMetadataName => {
299299
// split on the first colon, and then join the rest back together to support names that include colons
300-
const [typeName, ...name] = rawEntry.split(':').map((entry) => entry.trim());
301-
const type = reg.getTypeByName(typeName);
302-
const parent = reg.getParentType(typeName);
300+
const [typeName, ...name] = rawEntry.split(':');
301+
const type = reg.getTypeByName(typeName.trim());
302+
const parent = reg.getParentType(type.name);
303303
// If a user is requesting a child type that is unaddressable (more common with custom registries to create proper behavior)
304304
// throw an error letting them know to use the entire parent instead
305305
// or if they're requesting a COFT, unadressable without parent, don't throw because the parent could be requested - we don't know at this point
306306
if (type.isAddressable === false && parent !== undefined && !type.unaddressableWithoutParent) {
307307
throw new Error(`Cannot use this type, instead use ${parent.name}`);
308308
}
309-
return { type, metadataName: name.length ? name.join(':') : '*' };
309+
return { type, metadataName: name.length ? name.join(':').trim() : '*' };
310310
};
311311

312312
const typeAndNameToMetadataComponents =

test/collections/componentSetBuilder.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,34 @@ describe('entryToTypeAndName', () => {
546546
metadataName: '*',
547547
});
548548
});
549+
it('leading spaces in name are trimmed', () => {
550+
expect(entryToTypeAndName(reg)('Layout: My Layout')).to.deep.equal({
551+
type: reg.getTypeByName('Layout'),
552+
metadataName: 'My Layout',
553+
});
554+
});
555+
it('trailing spaces in name are trimmed', () => {
556+
expect(entryToTypeAndName(reg)('Layout:My Layout ')).to.deep.equal({
557+
type: reg.getTypeByName('Layout'),
558+
metadataName: 'My Layout',
559+
});
560+
});
561+
it('spaces in name', () => {
562+
expect(entryToTypeAndName(reg)('Layout:My Layout')).to.deep.equal({
563+
type: reg.getTypeByName('Layout'),
564+
metadataName: 'My Layout',
565+
});
566+
});
567+
it('colons in name', () => {
568+
expect(entryToTypeAndName(reg)('Layout:My:Colon:Layout')).to.deep.equal({
569+
type: reg.getTypeByName('Layout'),
570+
metadataName: 'My:Colon:Layout',
571+
});
572+
});
573+
it('colons and spaces in name', () => {
574+
expect(entryToTypeAndName(reg)('Layout:My : Colon : Layout')).to.deep.equal({
575+
type: reg.getTypeByName('Layout'),
576+
metadataName: 'My : Colon : Layout',
577+
});
578+
});
549579
});

0 commit comments

Comments
 (0)