diff --git a/src/collections/componentSetBuilder.ts b/src/collections/componentSetBuilder.ts index 9d8827cc65..829127c56d 100644 --- a/src/collections/componentSetBuilder.ts +++ b/src/collections/componentSetBuilder.ts @@ -297,16 +297,16 @@ export const entryToTypeAndName = (reg: RegistryAccess) => (rawEntry: string): MetadataTypeAndMetadataName => { // split on the first colon, and then join the rest back together to support names that include colons - const [typeName, ...name] = rawEntry.split(':').map((entry) => entry.trim()); - const type = reg.getTypeByName(typeName); - const parent = reg.getParentType(typeName); + const [typeName, ...name] = rawEntry.split(':'); + const type = reg.getTypeByName(typeName.trim()); + const parent = reg.getParentType(type.name); // If a user is requesting a child type that is unaddressable (more common with custom registries to create proper behavior) // throw an error letting them know to use the entire parent instead // 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 if (type.isAddressable === false && parent !== undefined && !type.unaddressableWithoutParent) { throw new Error(`Cannot use this type, instead use ${parent.name}`); } - return { type, metadataName: name.length ? name.join(':') : '*' }; + return { type, metadataName: name.length ? name.join(':').trim() : '*' }; }; const typeAndNameToMetadataComponents = diff --git a/test/collections/componentSetBuilder.test.ts b/test/collections/componentSetBuilder.test.ts index dfb97aec47..84b7cdc010 100644 --- a/test/collections/componentSetBuilder.test.ts +++ b/test/collections/componentSetBuilder.test.ts @@ -546,4 +546,34 @@ describe('entryToTypeAndName', () => { metadataName: '*', }); }); + it('leading spaces in name are trimmed', () => { + expect(entryToTypeAndName(reg)('Layout: My Layout')).to.deep.equal({ + type: reg.getTypeByName('Layout'), + metadataName: 'My Layout', + }); + }); + it('trailing spaces in name are trimmed', () => { + expect(entryToTypeAndName(reg)('Layout:My Layout ')).to.deep.equal({ + type: reg.getTypeByName('Layout'), + metadataName: 'My Layout', + }); + }); + it('spaces in name', () => { + expect(entryToTypeAndName(reg)('Layout:My Layout')).to.deep.equal({ + type: reg.getTypeByName('Layout'), + metadataName: 'My Layout', + }); + }); + it('colons in name', () => { + expect(entryToTypeAndName(reg)('Layout:My:Colon:Layout')).to.deep.equal({ + type: reg.getTypeByName('Layout'), + metadataName: 'My:Colon:Layout', + }); + }); + it('colons and spaces in name', () => { + expect(entryToTypeAndName(reg)('Layout:My : Colon : Layout')).to.deep.equal({ + type: reg.getTypeByName('Layout'), + metadataName: 'My : Colon : Layout', + }); + }); });