flitbit / json-ptr

A complete implementation of JSON Pointer (RFC 6901) for nodejs and modern browsers.
MIT License
91 stars 28 forks source link

Literal property value 'e' is interpreted as a number #48

Closed kamsar closed 2 years ago

kamsar commented 2 years ago

It appears that 'e' in a pointer path is interpreted as a number, which seems wrong since JS does not generally treat 'e' as a constant number and exponential notation requires a preceding digit ('1e7'). Adding an extra non-numeric character to the path, i.e. '/hi/eX', makes it behave as expected.

const { JsonPointer } = require('json-ptr');

// run `node index.js` in the terminal to repro

const obj = {};

const ptr = JsonPointer.create('/hi/e');

ptr.set(obj, 'hello', true);

console.log(`result`, obj);

// expected:
// { hi: {e: 'hello'} }

// got:
// { hi: [] }

Run it here: https://stackblitz.com/edit/node-a9wd7r?file=index.js

kamsar commented 2 years ago

This can also be reproduced with other single-character property names such as 'x' that are not numbers so it may just be a bug not related to number parsing at all.

cerebralkungfu commented 2 years ago

verified in branch bug/issue-48

running examples/issues/issue-48.js illustrates... thanks for the working code to reproduce!

I'll fix it there.

cerebralkungfu commented 2 years ago

Fixed in v3.1.0