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

strict option: no_duplicate_keys #104

Open
andreineculau opened this issue Dec 15, 2016 · 5 comments
Open

strict option: no_duplicate_keys #104

andreineculau opened this issue Dec 15, 2016 · 5 comments

Comments

@andreineculau
Copy link

as per https://tools.ietf.org/html/rfc7159#section-4

The names within an object SHOULD be unique.

yet JSX works like this:

1> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>).
[{<<"a">>,<<"b">>},{<<"a">>,<<"c">>}]

Consider adding no_duplicate_keys as as flag part of the strict option, or similar.

@talentdeficit
Copy link
Owner

i'll look at adding this to the in progress 3.0

probably won't backport it to 2.x tho, because there's no low impact way to track multiple keys when decoding to a map

@andreineculau
Copy link
Author

how is "there's no low impact way..." relevant if we're talking about adding a flag? current performance can stay the same, but those who want no_duplicate_keys can deal with whatever "performance" loss?

@andreineculau
Copy link
Author

a friendly bump. what's the status on this? thanks!

@paulo-ferraz-oliveira
Copy link
Contributor

@andreineculau: is this still an issue (it's been more than 2 years)? How would you go about detecting the duplicates? I imagine a map, since a list would be even more performance-degrading. Is this what you mean by your question? You'd like a flag and then a runtime validation if that flag was active. Is that it?

@andreineculau
Copy link
Author

@paulo-ferraz-oliveira I missed your comment, sorry. But yes, I think it's still an issue.

jsx@3.1.0 behaviour is unchanged

1> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>).
#{<<"a">> => <<"c">>}
2> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>, [{return_maps, false}]).
[{<<"a">>,<<"b">>},{<<"a">>,<<"c">>}]

from jsx@2.8.0

1> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>).
[{<<"a">>,<<"b">>},{<<"a">>,<<"c">>}]
2> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>, [{return_maps, true}]).
#{<<"a">> => <<"c">>}

For starters, it would be good if there's no behaviour difference dictated by return_maps.
At this point, it is "better" to return_maps: false and do the validation outside of JSX, because when returning maps, there's simply no way to detect duplicate keys.

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

No branches or pull requests

3 participants