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

Remove fails if the value for the key is undefined. #38

Open
DaveEmmerson opened this issue Sep 29, 2017 · 1 comment
Open

Remove fails if the value for the key is undefined. #38

DaveEmmerson opened this issue Sep 29, 2017 · 1 comment

Comments

@DaveEmmerson
Copy link

A { a: undefined }
B {}
patch = diff(A,B) (results in 'remove a')
patchInPlace(patch, A)

fails with "path does not exist"

// key must exist for remove
if(notFound(pointer) || pointer.target[pointer.key] === void 0) {
	throw new InvalidPatchOperationError('path does not exist ' + change.path);
}

The cause is the check for pointer.target[pointer.key] not being undefined.
The key needs to be present, but if the value is undefined that shouldn't prevent a removal.

@hollandjake
Copy link

Issue still exists.

While technically undefined is not a supported type in JSON, it is supported in JavaScript, possibly we could enable a flag in the options to allow this behaviour.

Current code has the issue triggering at

jiff/lib/patches.js

Lines 180 to 182 in 035d5ac

if(change.value === void 0) {
throw new InvalidPatchOperationError('missing value');
}

This would also need to be reflected in the type hints as currently we only allow null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants