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

TypeError exception on array comparison #85

Closed
febeling opened this issue Nov 5, 2015 · 6 comments
Closed

TypeError exception on array comparison #85

febeling opened this issue Nov 5, 2015 · 6 comments
Assignees

Comments

@febeling
Copy link

febeling commented Nov 5, 2015

This test passes with 0.5.4 and fails with 0.5.5

    it('jsonpatch array compare', function () {
      var a = ['foo', 'bar']
      var b = ['foo', 'bar', 'baz']

      expect(jsonpatch.compare(b, a)).toEqual([
        { op: 'remove', path: '/2' }
      ])
      expect(jsonpatch.compare(a, b)).toEqual([
        { op: 'add', path: '/2', value: 'baz' }
      ])
    })

This is the stacktrace:

PhantomJS 1.9.8 (Mac OS X 0.0.0) Service: utility changes to get from updated to original jsonpatch array compare FAILED
    TypeError: '[object Object]' is not a valid argument for 'Function.prototype.apply' (evaluating 'obj.length')
        at /Users/febeling/work/ehealth/sl-ebola-call-admin/app/bower_components/fast-json-patch/src/json-patch-duplex.js:29
        at _generate (/Users/febeling/work/ehealth/sl-ebola-call-admin/app/bower_components/fast-json-patch/src/json-patch-duplex.js:405)
        at compare (/Users/febeling/work/ehealth/sl-ebola-call-admin/app/bower_components/fast-json-patch/src/json-patch-duplex.js:537)
        at /Users/febeling/work/ehealth/sl-ebola-call-admin/test/spec/services/utility.js:117

Updated: showing tests exercising the library API directly, instead of our thin service layer.

@warpech
Copy link
Collaborator

warpech commented Nov 6, 2015

@miyconst could you please take a look?

@miyconst
Copy link
Collaborator

miyconst commented Nov 6, 2015

Sure.

@miyconst miyconst self-assigned this Nov 6, 2015
@miyconst
Copy link
Collaborator

miyconst commented Nov 6, 2015

@febeling, could you please provide your full testing environment?

And could you try to replace

return Array.apply(null, { length: obj.length }).map(function (e, i, a) { return i.toString(); });

at https://github.com/Starcounter-Jack/JSON-Patch/blob/master/src/json-patch-duplex.js#L29

with

var keys = new Array(obj.length);

for (var i = 0; i < keys.length; i++) {
    keys[i] = i.toString();
}

return keys;

And let me know whether it passes.

@febeling
Copy link
Author

febeling commented Nov 6, 2015

The tests are written with jasmine and run in karma, controlling a phantomjs browser runtime.

I can't reproduce the problem in plain node.

The problem goes away when switching karma to use Chrome as browser runtime.

With the change to loop iteration you propose above it also works with phantomjs.

miyconst pushed a commit that referenced this issue Nov 7, 2015
@miyconst
Copy link
Collaborator

miyconst commented Nov 7, 2015

Should be fixed in 0.5.6

@miyconst miyconst closed this as completed Nov 7, 2015
@febeling
Copy link
Author

febeling commented Nov 7, 2015

Confirming the fix. Thanks!

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

3 participants