Giter Club home page Giter Club logo

json-pointer's Issues

compile([]) returns "/"

I believe it should return the empty string instead.

parse() behaves correctly:

var jsonPointer = require('json-pointer');
jsonPointer.parse('');  // []
jsonPointer.parse('/'); // ['']

But they don't match up:

jsonPointer.compile(jsonPointer.parse('')) !== '';

#dict is not working with empty arrays

dict doesn't return property if its value is an empty array, but #has checks that it exists.

jsp = require "json-pointer"
console.dir jsp.has  { a: "x", b: [] }, "/b"
console.dir jsp.dict { a: "x", b: [] }

returns:

true
{ '/a': 'x' }

Got a license for this?

Very nice implementation, clean, useful methods, well documented.

I was wondering if you had a license in mind because I'd like to copy this code into my client side google closure library and tweak it to match the style and namespacing there, if it'd be OK. I would of course leave a comment in the file back to this repo as the original source.

CVE-2021-23820

+--------------+------------------+----------+-------------------+---------------+---------------------------------------+
|   LIBRARY    | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION |                 TITLE                 |
+--------------+------------------+----------+-------------------+---------------+---------------------------------------+
| json-pointer | CVE-2021-23820   | CRITICAL | 0.6.1             |               | Prototype Pollution in json-pointer   |
|              |                  |          |                   |               | -->avd.aquasec.com/nvd/cve-2021-23820 |
+--------------+------------------+----------+-------------------+---------------+---------------------------------------+

GHSA-v5vg-g7rq-363w

The pointer.dict function crashes when object contains an array

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)

Selector support and docs

Pointer arguments should be called Selectors, to remove ambiguity between the method and the arguments.

Also on readme/documentation, would be nice to list the rules of these selectors, so we know how to query and what possibilities we have

Missing remove()

Hi - I just started using your library for something, and I realised I can get(), and I can set(), but I'd like to be able to remove().

Any chance of putting that in?

Funky whitespace in api.walk

There's some odd whitespace in line 130 that happens to work fine in Node but breaks when run in the browser via browserify.

Support relative pointers?

https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01

I have an implementation here. https://github.com/mokkabonna/json-hyper-schema/blob/master/src/relative-json-pointer.js complete with tests: https://github.com/mokkabonna/json-hyper-schema/blob/master/test/specs/relative-json-pointer.spec.js

Would you be willing to implement that in this library? If so I can make a PR.

If not I will publish my implementation as a separate library. I anyway depend on your implementation.

Add thrown exceptions in documentation

Can you improve the documentation and add what exceptions are thrown and why?
For example if you use get with a non existing reference token, the function will throw an Error the a message saying "Invalid reference token: foo".

It's too bad I have to browse the code or the unit tests to figure out what is the basic behavior of the functions.

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.