Skip to content

Commit

Permalink
fix Replace op with value of empty object results in circular referen…
Browse files Browse the repository at this point in the history
…ce (#527)

Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant authored Oct 23, 2023
1 parent f58de7a commit 731bc94
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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": "[email protected]",
"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

0 comments on commit 731bc94

Please sign in to comment.