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

The pointer.dict function crashes when object contains an array #2

Closed
maxkueng opened this issue Sep 7, 2013 · 3 comments
Closed

Comments

@maxkueng
Copy link

maxkueng commented Sep 7, 2013

Hey

it seem like json-pointer can't handle arrays inside objects very well. Using the dict method, it produces an error when trying to replace array keys.

var pointer = require('json-pointer');

var obj = {
    bla : {
        bli : [4, 5, 6]
    }
};

console.log(pointer.dict(obj));

I got the following error:

/tmp/pntr/node_modules/json-pointer/index.js:143
    return str.replace(/~/g, '~0').replace(/\//g, '~1');
               ^
TypeError: Object 0 has no method 'replace'
    at escape (/tmp/pntr/node_modules/json-pointer/index.js:143:16)
    at Array.map (native)
    at Function.compile (/tmp/pntr/node_modules/json-pointer/index.js:175:28)
    at mapObj (/tmp/pntr/node_modules/json-pointer/index.js:101:29)
    at /tmp/pntr/node_modules/json-pointer/index.js:96:21
    at forEach (/tmp/pntr/node_modules/json-pointer/node_modules/foreach/index.js:12:16)
    at mapObj (/tmp/pntr/node_modules/json-pointer/index.js:94:17)
    at /tmp/pntr/node_modules/json-pointer/index.js:96:21
    at forEach (/tmp/pntr/node_modules/json-pointer/node_modules/foreach/index.js:17:20)
    at mapObj (/tmp/pntr/node_modules/json-pointer/index.js:94:17)
manuelstofer added a commit that referenced this issue Sep 8, 2013
@manuelstofer
Copy link
Owner

I added a test for your example. It seems to work for me.

Do you have more infos how i can reconstruct this problem?

@maxkueng
Copy link
Author

maxkueng commented Sep 8, 2013

I used the latest version on npm (v0.0.3) and was able to produce the error with the exact same code as above and in your test. But I have just tried it with your latest master branch and the error doesn't occur any more.

The relevant line is index.js:104 in api.dict where the key in converted into a string. In v0.0.3 key wasn't necessarily a string so api.escape couldn't call the replace function in case it was a number.

v0.0.3 on npm:

refTokens.push(key);

on master:

refTokens.push(String(key));

So it seems you have already fixed it but not published to npm yet.

All is good thanks! :)

@maxkueng maxkueng closed this as completed Sep 8, 2013
@manuelstofer
Copy link
Owner

Jepp, forgot to publish, thanks! I just published 0.0.4 on npm

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