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 Replace op with value of empty object results in circular reference #527

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/scimPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ function addOrReplaceObjectAttribute(property: any, patch: ScimPatchAddReplaceOp
return patch.value;
}

// fix https://github.com/thomaspoignant/scim-patch/issues/489
// when trying to insert an empty object, we should directly insert it without merging.
if (Object.keys(patch.value).length === 0) {
return {};
}

// We add all the patch values to the property object.
for (const [key, value] of Object.entries(patch.value)) {
assign(property, resolvePaths(key), value, patch.op);
Expand Down
18 changes: 17 additions & 1 deletion test/scimPatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('SCIM PATCH', () => {
return done();
});


it('REPLACE: first level property without path', done => {
const expected = false;
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: {active: expected}};
Expand Down Expand Up @@ -348,6 +347,23 @@ describe('SCIM PATCH', () => {
return done();
});

// see https://github.com/thomaspoignant/scim-patch/issues/489
it('REPLACE: Replace op with value of empty object results in circular reference', done => {
const expected = [
{
"value": "spiderman@superheroes.com",
"primary": true
},
{
"type": "work",
value: {}
}
];
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: {}, path: 'emails[type eq "work"].value'};
const afterPatch = scimPatch(scimUser, [patch], { mutateDocument: false, treatMissingAsAdd: true });
expect(afterPatch.emails).to.be.deep.eq(expected);
return done();
});
});

describe('add', () => {
Expand Down