Skip to content

Commit

Permalink
fix: match using decoded component keys in ComponentSet.has()
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Aug 8, 2023
1 parent 88f711e commit 7de0a8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
return true;
}

// This will decode the key of the component before comparing, which can solve some edge cases
// in component fullNames such as Layouts. See: https://github.com/forcedotcom/cli/issues/1683
const isDirectlyInSetDecoded = this.components.has(decodeURI(simpleKey(component)));
if (isDirectlyInSetDecoded) {
return true;
}

const wildcardMember: ComponentLike = {
fullName: ComponentSet.WILDCARD,
type: typeof component.type === 'object' ? component.type.name : component.type,
Expand Down
20 changes: 20 additions & 0 deletions test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,26 @@ describe('ComponentSet', () => {

expect(set.has(child)).to.be.true;
});

it('should correctly evaluate membership with decoded MetadataComponent key', () => {
const set = new ComponentSet(undefined, registryAccess);
const decodedComponent: MetadataComponent = {
fullName: 'Broker__c-v1.1 Broker Layout',
type: registry.types.layout,
};
const encodedComponent: MetadataComponent = {
fullName: 'Broker__c-v1%2E1 Broker Layout',
type: registry.types.layout,
};

expect(set.has(decodedComponent)).to.be.false;
expect(set.has(encodedComponent)).to.be.false;

set.add(decodedComponent);

expect(set.has(encodedComponent)).to.be.true;
expect(set.has(decodedComponent)).to.be.true;
});
});

it('should calculate size correctly', () => {
Expand Down

0 comments on commit 7de0a8a

Please sign in to comment.