Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: match using decoded component keys in ComponentSet.has() #1070

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
*
* A pair is considered present in the set if one of the following criteria is met:
*
* - The pair is directly in the set
* - The pair is directly in the set, matching the component key "as is" or decoded.
* - A wildcard component with the same `type` as the pair
* - If a parent is attached to the pair and the parent is directly in the set
* - If a parent is attached to the pair, and a wildcard component's `type` matches the parent's `type`
Expand All @@ -542,8 +542,10 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
* @returns `true` if the component is in the set
*/
public has(component: ComponentLike): boolean {
const isDirectlyInSet = this.components.has(simpleKey(component));
if (isDirectlyInSet) {
// Compare the component key as is and decoded. Decoding the key before comparing can solve some edge cases
// in component fullNames such as Layouts. See: https://github.com/forcedotcom/cli/issues/1683
const key = simpleKey(component);
if (this.components.has(key) || this.components.has(decodeURI(key))) {
return true;
}

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