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

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

Closed
kamsar opened this issue Jan 18, 2022 · 3 comments
Closed

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

kamsar opened this issue Jan 18, 2022 · 3 comments
Assignees
Labels

Comments

@kamsar
Copy link

kamsar commented Jan 18, 2022

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
Copy link
Author

kamsar commented Jan 18, 2022

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 cerebralkungfu self-assigned this Feb 2, 2022
cerebralkungfu pushed a commit that referenced this issue Feb 2, 2022
@cerebralkungfu
Copy link
Contributor

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 pushed a commit that referenced this issue Feb 2, 2022
@cerebralkungfu
Copy link
Contributor

cerebralkungfu commented Feb 2, 2022

Fixed in v3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants