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

'duplicated mapping key' error with unique keys #573

Closed
MGough opened this issue Aug 7, 2020 · 4 comments
Closed

'duplicated mapping key' error with unique keys #573

MGough opened this issue Aug 7, 2020 · 4 comments

Comments

@MGough
Copy link

MGough commented Aug 7, 2020

I think I've found an issue when dealing with a YAML mapping containing a large number of keys.

This can be reproduced by running this minimal example through the JS-YAML Demo

This is my minimal example (I'm not including it as a code block here due to the number of lines):
https://gist.github.com/MGough/e38b2cf7b41c151ba8216b77a08c9177

It looks almost like a hash conflict, once the final key/value pair is removed the issue goes away. You can remove a different key value pair and the issue persists. From what I can tell there aren't any duplicate keys. This was also an issue when there were more keys after the final one in this example, I've just removed them as they were redundant.

@MGough
Copy link
Author

MGough commented Aug 7, 2020

Seems like it's not specific to the number of keys, I'm guessing it's something else I've missed perhaps like a whitespace issue. Although other YAML validators online show it as valid

@puzrin
Copy link
Member

puzrin commented Aug 7, 2020

Minimized example

10513478508167781E58455: 2335
11193430644352832E11281: 2452

both keys => big integers in scientific notation (10513478508167781 e 58455) => Infinity => duplicated infinity.

Seems work as expected. Who generated this yaml data? I would strongly recommend to quote keys. May be other langs can each huge numbers, but JS - no.

@MGough
Copy link
Author

MGough commented Aug 7, 2020

Thank you! Apologies for bringing you an issue that's ultimately not yours, my lack of JS expertise would've had me working on that for days 😆 . I hadn't spotted the E at all.

As for where it came from, it was actually generated using the python yaml library. I think what has happened is that the python yaml library quite happily serialized a python dict, which can have any object as a key, rather than serializing JSON.

@MGough MGough closed this as completed Aug 7, 2020
@puzrin
Copy link
Member

puzrin commented Aug 7, 2020

yaml/pyyaml#173 AFAIK, there may be difference between spec and real code due need of JSON compatibility. But i don't remember details.

In theory, according to spec, your dump is correct, because scientific notation must have sign before exponent: 1e+5. BUT json is ok without sign too (and YAML is declared as JSON-compatible):

node -e 'console.log(JSON.parse("1e5"))'

If anyone wish dive into spec & propose changes - i'm open to suggestions.

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