kastnermario / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Input strings with quotes give artifacts in output #202

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The code below shows this error. (using version 0.5.1)

    YAML::Node n(YAML::Load("YAML: \"test\""));
    YAML::Emitter em;
    em << n;    
    std::string mystr(em.c_str());
    std::cout << mystr << std::endl;

What it outputs is:
YAML: !<!> test

The exclamation marks are not supposed to be there. This problem is magnified 
if you set the options to add quotes around strings in the output. In that case 
a round trip (read-write-read-write) will add more and more exclamation marks.

Original issue reported on code.google.com by pweijt...@gmail.com on 21 Apr 2013 at 8:55

GoogleCodeExporter commented 8 years ago
Yeah, this is a problem. Thanks.

Original comment by jbe...@gmail.com on 3 May 2013 at 1:10

GoogleCodeExporter commented 8 years ago
Another example (a case where python's yaml module will read the deserialized 
version differently, essentially corrupting the data). Consider the code:
    YAML::Node n1 = YAML::Load("x: ''"); 
    cout << n1;
The output is:
    x: !<!> ""

From my understanding of spec it seems "!<!>" is an invalid verbatim tag 
(http://www.yaml.org/spec/1.2/spec.html#id2784064), so behavior of other 
language's yaml parser might be undefined when parsing such strings (e.g., 
Python parses the above value as "None" (null): 
http://yaml-online-parser.appspot.com/?yaml=x%3A+!%3C!%3E+%22%22&type=json). 
So effectively, the original yaml data is mangled after deserialization (which 
different parsers can read differently, or even refuse to read altogether).

Any temporary hack/suggestions to work around this problem is greatly 
appreciated. Thanks a ton!

Original comment by abiy...@23andme.com on 5 Nov 2013 at 9:50

GoogleCodeExporter commented 8 years ago
Issue 263 has been merged into this issue.

Original comment by jbe...@gmail.com on 24 Dec 2014 at 6:41

GoogleCodeExporter commented 8 years ago
This issue has moved to github: https://github.com/jbeder/yaml-cpp/issues/202

Original comment by jbe...@gmail.com on 1 Apr 2015 at 3:22