yeison / snakeyaml

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

Directives lost between documents against spec #149

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
-> What steps will reproduce the problem?
1. Create a multi-document YAML stream that uses Named Tag Handles 
(http://www.yaml.org/spec/1.2/spec.html#id2783028) for each document start. 
Example document is attached.
2. Load it with yaml.loadAll(...);
3. The parser will choke on an unrecognized tag after the first document.

-> What is the expected output? What do you see instead?

Expected behaviour: 
  Directives from the first explicit document in a multi-document stream should carry forward to the following documents. 

Current behaviour:
  When I call yaml.loadAll(...), it's fine for the first Document in the stream. On the next one, I get a ParserException that complains that it "found undefined tag handle !u!". Upon searching variables, it is true that !u! disappears from the tagHandles instance variable in org.yaml.snakeyaml.parser.ParserImpl. This looks to be because processDirectives() is called every document and it trashes the old tagHandles list.

From my reading of the YAML spec (http://yaml.org/spec/1.1/#id898785), it's 
supposed to preserve directives between documents:

  "To ease the task of concatenating character streams, following documents may begin with a byte order mark and comments, though the same character encoding must be used through the stream. Each following document must be explicit (begin with a document start marker). If the document specifies no directives, it is parsed using the same settings as the previous document. If the document does specify any directives, all directives of previous documents, if any, are ignored." 

-> What version of SnakeYAML are you using? On what Java version?
  Java 1.6 update 32
  SnakeYAML 1.10

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

Dicussion started before ticket creation: 
  http://groups.google.com/group/snakeyaml-core/browse_thread/thread/ab71f171800af822

I've also attached a code sketch (not actually runnable) to give an idea of how 
I'm calling this.

Original issue reported on code.google.com by robinETm...@gmail.com on 6 Jun 2012 at 7:50

Attachments:

GoogleCodeExporter commented 9 years ago
I've gotten a fairly simple workaround for this: I read in the file and do some 
string manipulations on it to: split each document into a separate string, and 
then prepend the original directives to each string. Then, for each string, 
yaml.load(str).

Original comment by robinETm...@gmail.com on 8 Jun 2012 at 6:41

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Started.
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue149/GlobalDirectivesTest.java

Original comment by py4fun@gmail.com on 11 Jun 2012 at 5:33

GoogleCodeExporter commented 9 years ago
Fixed. Feel free to test the source. This YAML is parsed without errors:
http://code.google.com/p/snakeyaml/source/browse/src/test/resources/issues/issue
149-losing-directives.yaml

The fix will be delivered in version 1.11

A few conclusions:
1) PyYAML has the same problem. If this YAML document has to be parsed in 
Python, it may fail (I am not sure what happens if libyaml is used)
2) If the original YAML document was generated with yaml-cpp 
(http://code.google.com/p/yaml-cpp/) then you may get unexpected errors because 
yaml-cpp implements YAML 1.2 while SnakeYAML is still with YAML 1.1

Original comment by py4fun@gmail.com on 13 Jun 2012 at 11:33

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/snakeyaml/wiki/changes

Original comment by py4fun@gmail.com on 17 Jun 2012 at 10:43