yeison / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

Duplicate anchors in an input document should not be an error #174

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
* What steps will reproduce the problem?

1. Generate a document with duplicate anchors, for example the SnakeYAML test 
cases for checking that SnakeYAML produces an error on duplicate anchors.
2. Parse the document

* What is the expected output? What do you see instead?

Expected: The document parses without error.
Actual: SnakeYAML throws an exception.

* What version of SnakeYAML are you using? On what Java version?

SnakeYAML 1.12.  Java 1.6.

* Please provide any additional information below. (Often a failing test is
the best way to describe the problem.)

The YAML 1.1 specification section 3.2.2.2 explicitly notes: "anchors need not 
be unique within a serialization."  This does honestly seem like a bad idea, 
but the Ruby (1.8.7) YAML generator produces duplicate anchors, and consumes 
them again in a seemingly spec-compliant fashion.

Original issue reported on code.google.com by llas...@gmail.com on 1 Apr 2013 at 12:29

GoogleCodeExporter commented 9 years ago
The YAML parser in Ruby 1.8 has many deficiencies. So many that in Ruby 1.9 it 
is completely abandoned in favor of libyaml (psych).
Supporting weird features of Ruby 1.8 would create more problems for 1.9 and 
2.0 users.
I think the best way to continue is to mention this as yet another intentional 
deviation form the specification on the wiki 
(http://code.google.com/p/snakeyaml/wiki/Documentation#Deviations_from_the_speci
fication).

Original comment by py4fun@gmail.com on 1 Apr 2013 at 3:49

GoogleCodeExporter commented 9 years ago
Since the spec allows duplicate anchors, is it really "weird behavior"?  
Additionally, it seems very easy to support -- just comment out the check, and 
later anchors with the same ID replace existing anchors, as they are 
encountered.

Original comment by llas...@gmail.com on 1 Apr 2013 at 4:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Try to parse the YAML document with duplicate anchors with Ruby 1.9. If it does 
not work, then we can consider this as a bug which is fixed now in Ruby.
Otherwise, feel free to implement the fix in SnakeYAML.

Original comment by py4fun@gmail.com on 2 Apr 2013 at 4:52

GoogleCodeExporter commented 9 years ago
Ah, good check.  And the default Ruby 1.9 (1.9.3) YAML parser does accept them 
without complaint.  Patch attached, although I'm not certain the test case is 
done in the correct fashion to follow project conventions.

Original comment by llas...@gmail.com on 2 Apr 2013 at 11:32

Attachments:

GoogleCodeExporter commented 9 years ago
Give it a try:
http://code.google.com/p/snakeyaml/source/detail?r=cf3404e3b61d7c4fb1081291c3b75
5d2e1ae5fb4

Original comment by py4fun@gmail.com on 2 Apr 2013 at 9:51

GoogleCodeExporter commented 9 years ago
Yep -- lets me parse my problem input documents.  Thanks!

Original comment by llas...@gmail.com on 3 Apr 2013 at 2:11

GoogleCodeExporter commented 9 years ago
It will be delivered in version 1.13 (you can already try the 1.13-SNAPSHOT)

http://code.google.com/p/snakeyaml/wiki/changes

Original comment by py4fun@gmail.com on 3 Apr 2013 at 4:04