Skip to content

Fix(SCIMMY.Messages.PatchOp): empty array error on custom extension#106

Open
sp1r1t wants to merge 2 commits into
scimmyjs:mainfrom
sp1r1t:fix/patchop-remove-empty-extension-array-crash
Open

Fix(SCIMMY.Messages.PatchOp): empty array error on custom extension#106
sp1r1t wants to merge 2 commits into
scimmyjs:mainfrom
sp1r1t:fix/patchop-remove-empty-extension-array-crash

Conversation

@sp1r1t

@sp1r1t sp1r1t commented Apr 13, 2026

Copy link
Copy Markdown

When running a "Remove" patch operation on an array in a custom extension I get the error:

Cannot read properties of undefined (reading 'length')

The error arises in patchop.js on line 383:

patchop.js:380-383

// Filter out any values that exist in removals list
target[property] = (target[property] ?? []).filter(v => !removals.includes(v));
// Unset the property if it's now empty
if (target[property]).length === 0) target[property] = undefined; // <----

The issue arises because target[property] is a schema instance, which returns undefined when it has no values.

schema.js:204

if (!hasActualValues(resource[extension.id] ?? {})) return undefined;

This PR fixes the issue by safeguarding the .length call by coalescing to an empty array if target[property] is nullish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant