Coder Social home page Coder Social logo

Comments (10)

baranga avatar baranga commented on June 3, 2024

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.

MarkHerhold avatar MarkHerhold commented on June 3, 2024

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.

baranga avatar baranga commented on June 3, 2024

@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.

MarkHerhold avatar MarkHerhold commented on June 3, 2024

@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.

baranga avatar baranga commented on June 3, 2024

@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.

baranga avatar baranga commented on June 3, 2024

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.

baranga avatar baranga commented on June 3, 2024

@MarkHerhold So right now something broken can't be fixed because the lib supports a non standard feature?

from json-patch.

MarkHerhold avatar MarkHerhold commented on June 3, 2024

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.

warpech avatar warpech commented on June 3, 2024

The part regarding undefined is fixed in 1.0.0

from json-patch.

baranga avatar baranga commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.