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

Tests with repeated keys should be marked as errors #25

Open
eemeli opened this issue Feb 1, 2018 · 7 comments
Open

Tests with repeated keys should be marked as errors #25

eemeli opened this issue Feb 1, 2018 · 7 comments

Comments

@eemeli
Copy link
Member

eemeli commented Feb 1, 2018

Specifically, 2JQS has repeated empty keys and E76Z has an alias referring to another key in the same map. These are both errors, as the spec requires mapping keys to be unique.

@eemeli
Copy link
Member Author

eemeli commented Feb 1, 2018

Also test PW8X has repeated empty/null keys.

eemeli added a commit to eemeli/yaml-test-suite that referenced this issue Feb 3, 2018
@eemeli
Copy link
Member Author

eemeli commented Feb 18, 2018

X38W also has an alias referring to another key in the same map.

eemeli added a commit to eemeli/yaml-test-suite that referenced this issue Feb 18, 2018
@perlpunk
Copy link
Member

Thanks.
We were discussing duplicate keys several times, and came to the conclusion that it's not really definable what equality or duplicate actually means, at least not at the parser level.
http://yaml.org/spec/1.2/spec.html#id2764652

The parser can't (always) know if keys are considered equal or not.

For example:

# duplicate! right?
"blue": 1
blue: 2

# duplicate?
"true": 1
true: 2

# duplicate?
"3.14": 1
3.14: 2

# duplicate?
0x17: 1
23: 2

# duplicate?
? a: 1
  b: 2
: 1
? b: 2
  a: 1
: 2

Therefor, the constructor/schema has to define equality.
We could define for our test cases, that we apply the YAML Core Schema, and so can identify all cases with duplicate keys.

We still haven't decided how to mark loader/constructor errors; maybe with tags like error-loader.
We additionally have to consider YAML version differences.
Ideas welcome ;-)

@eemeli
Copy link
Member Author

eemeli commented Mar 18, 2018

Explicitly specifying the core schema for the tests sounds like a Good Idea; with that answering the equality of each of the above examples becomes straightforward:

  • blue: equal, !!str "blue"
  • true: not equal, !!str "true" vs. !!bool true
  • 3.14: not equal, !!str "3.14" vs. !!float 3.14
  • 23: equal, !!int 23
  • { a: 1, b: 2 }: equal, !!map { !!str "a" : !!int 1 , !!str "b" : !!int 2 } (key order does not matter)

@eemeli
Copy link
Member Author

eemeli commented Jul 1, 2018

As an update, this is still an issue with the tests 2JQS and PW8X due to their repeated empty/null keys.

eemeli added a commit to eemeli/yaml-test-suite that referenced this issue Jul 1, 2018
eemeli added a commit to eemeli/yaml-test-suite that referenced this issue Jul 8, 2018
@avonwyss
Copy link

Test E76Z is also still broken. This test uses an alias to an anchored key, so the key must be unambiguously the same by definition. However, since that test does test specific functionality and should therefore not just be marked as erroneous, therefore I'd suggest to change it like this:

--- in-yaml
&a a: &b b
*b : *a

--- in-json
{
  "a": "b",
  "b": "a"
}

@perlpunk perlpunk added this to Backlog in Release Planning Feb 16, 2020
@perlpunk
Copy link
Member

I marked the test with a duplicate-key tag, and it shows up as "not implemented" in https://matrix.yaml.io/
Hope that's ok now =)

@perlpunk perlpunk moved this from Backlog to In Progress/Review in Release Planning May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Release Planning
  
In Progress/Review
Development

Successfully merging a pull request may close this issue.

3 participants