Comments (10)
This also works with objects:
var jsonpatch = require('./src/json-patch');
var patches = [{op: 'add', value: {}, path: '/foo'}, {op: 'add', value: 'a', path: '/foo/a'}];
jsonpatch.validate(patches, {});
console.log(patches);
Output:
[ { op: 'add', value: { a: 'a' }, path: '/foo' },
{ op: 'add', value: 'a', path: '/foo/a' } ]
Looks like patch value gets copied by reference instead of deep copy.
from json-patch.
How does this work with undefined values? IIRC, this repo tries to respect
undefined fields despite them not being serializable to/from JSON (which is
a bad idea anyway IMO) .
On Tue, May 3, 2016, 9:53 AM baranga [email protected] wrote:
This also works with objects:
var jsonpatch = require('./src/json-patch');
var patches = [{op: 'add', value: {}, path: '/foo'}, {op: 'add', value: 'a', path: '/foo/a'}];
jsonpatch.validate(patches, {});
console.log(patches);Looks like patch value gets copied by reference instead of deep copy.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#76 (comment)
from json-patch.
@MarkHerhold I don't understand your question. How to deep copy something with a undefined
in it? That should not happen because you can not express a patch operation with value of undefined
.
from json-patch.
@baranga You are right, it shouldn't happen in the traditional JSON sense, but JSON-Patch treats undefined
as a first-class citizen. ;)
Here's an example:
> var jsonpatch = require('fast-json-patch')
undefined
> var obj = {};
undefined
> jsonpatch.apply(obj, [{op: 'add', path:"/thing", value: undefined}]);
true
> Object.keys(obj)
[ 'thing' ]
> obj.thing
undefined
See also #90 #60 #32 and probably others...
from json-patch.
@MarkHerhold That still works. deepClone
only does a JSON encode/decode roundtrip if value is of type object
. See json-patch-duplex.ts.
Is that behaviour covered by the test suites? I run them with my modifications and got same errors as on master.
from json-patch.
Ok, now I see the issue:
> var jsonpatch = require('./src/json-patch-duplex')
undefined
> var obj = {}
undefined
> jsonpatch.apply(obj, [{op: 'add', path: '/deepThing', value: {undef: undefined}}])
true
> Object.keys(obj)
[ 'deepThing' ]
> Object.keys(obj.deepThing)
[]
But the last should be:
> Object.keys(obj.deepThing)
[ 'undef' ]
from json-patch.
@MarkHerhold So right now something broken can't be fixed because the lib supports a non standard feature?
from json-patch.
No, there are other more expensive clone strategies and implementations.
e.g. lodash's clone.
I personally think we should cut a v1 release, dropping support for
undefined and apply your PR.
On Wed, May 4, 2016, 3:19 AM baranga [email protected] wrote:
@MarkHerhold https://github.com/MarkHerhold So right now something
broken can't be fixed because the lib supports a non standard feature?—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#76 (comment)
from json-patch.
The part regarding undefined
is fixed in 1.0.0
from json-patch.
This issue is still present. I updated my possible fix #100 to newest version: #134. This comes with a speed penalty.
from json-patch.
Related Issues (20)
- Add user-defined hooks into the deepClone function
- Inefficient patch encoding when prepending to arrays HOT 2
- rrrr HOT 1
- Add performance comparison with jsondiffpatch
- Array patching, over empty elements.. HOT 2
- Any plans for a new release? HOT 1
- Maybe it's already discussed, but anyone think of how to patch array member in a more flexible approach?
- Release 3.1.1 request based on PR merged of #262 HOT 2
- Inaccurate documentation HOT 1
- Error index always 0? HOT 1
- Optional observe callback not called HOT 1
- applyPatch() validator index is not incrementing
- Backport fix for GHSA-8gh8-hqwg-xf34 to v2 HOT 5
- package.json should use `conditional exports`, else esm won't work inexplicitly HOT 1
- Node12+ import documentation incorrect
- Documentation for `generate` mentions wrong signature
- auto add tests to "add/remove" operations like for "replace"
- Mixing default exports and named exports breaks parcel HOT 2
- Attempting to use if mirror has a toJSON and object does not breaks HOT 2
- applying a replace patch is inconsistent with path="" and path="/"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-patch.