marcusaram / snakeyaml

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

Dumping a string with line breaks can result in garbage #52

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a Java String with line breaks (aka '\n')
2. set the width of the DumperOptions to a value that will break the given 
string just at a line break
3. use the double quoted style

What is the expected output? What do you see instead?
The expected output would be the very same string input.
The special characters of the  Java String get escaped with the double quoted 
style, so a line break will 
become to '\\n'. If the width setting of the DumperOptions is accidentally 
inserting a line break inside 
this character sequence the meaning of \n is lost so when loading the dumped 
string afterwards you 
get a straying '\' inside your final string.

What version of the product are you using? On what operating system?
SnakeYaml 1.5 with Java 1.5 on OS X 10.5.8

Please provide any additional information below.
-

Original issue reported on code.google.com by johann.W...@nureg.de on 15 Feb 2010 at 10:38

GoogleCodeExporter commented 9 years ago
Can you please modify the attached test case that it works/fails as you expect ?

(please note that the etalon and parsed string are identical at the end)

Original comment by aso...@gmail.com on 15 Feb 2010 at 6:28

Attachments:

GoogleCodeExporter commented 9 years ago
Making a yaml.dump and a yaml.load directly afterwards I could not reproduce 
the error. It seems I am missing 
something but I get a wrong representation when I use e.g. the string

"<tag>content string</tag>\n<anothertag>other content</anothertag>\n  
\n<i>new</i>\n"

which gets dumped to

--- "<tag>content\
  \ string</tag>\n\
  <anothertag>other\
  \ content</anothertag>\n\
  \  \n<i>new</i>\n"

using

DumperOptions yamlOptions = new DumperOptions();
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.AUTO);
yamlOptions.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
yamlOptions.setExplicitStart(true);
yamlOptions.setWidth(10);

When I load this dumped string in Perl using YAML::Syck I get the following 
result:

<tag>content\ string</tag>
<anothertag>other\ content</anothertag>
\  
<i>new</i>

you can see there are three '\' characters which shouldn't be there.

Original comment by johann.W...@nureg.de on 18 Feb 2010 at 4:10

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
It is a bug in Perl.
Try to change the output in a way that YAML::Syck can understand it.

Original comment by py4fun@gmail.com on 18 Feb 2010 at 6:26

GoogleCodeExporter commented 9 years ago
You are right. I tried the loading with a different Perl module and this time 
the output was correct.
So this bug report can be closed.

Original comment by johann.W...@nureg.de on 18 Feb 2010 at 11:34

GoogleCodeExporter commented 9 years ago

Original comment by aso...@gmail.com on 19 Feb 2010 at 8:10