cuizhennan / snakeyaml

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

Cannot load document with a string value of "=" #192

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following document will no load with SnakeYaml:

---
part1: =

This is a valid YAML document though. It should interpret the equals sign as a 
string.

SnakeYAML 1.8 and 1.13
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Original issue reported on code.google.com by Marc.OMo...@swrve.com on 22 May 2014 at 9:03

Attachments:

GoogleCodeExporter commented 9 years ago
Attaching example YAML file

Original comment by Marc.OMo...@swrve.com on 22 May 2014 at 9:04

Attachments:

GoogleCodeExporter commented 9 years ago
Well, the YAML is invalid. PyYAML gives the same result:

The document is not valid YAML:
could not determine a constructor for the tag 'tag:yaml.org,2002:value'
  in "", line 2, column 8:
    part1: =
           ^
---
part1: =

It will take time to find the exact reason in the specification:
http://yaml.org/spec/1.1/

You can solve it by using quotes:

---
part1: '='

Original comment by py4fun@gmail.com on 22 May 2014 at 1:05

GoogleCodeExporter commented 9 years ago
I see the same bug was logged against PyYAML though: 
http://pyyaml.org/ticket/140

Original comment by Marc.OMo...@swrve.com on 22 May 2014 at 1:13

GoogleCodeExporter commented 9 years ago
I can't put quotes around the = sign, since the document that I have is being 
generated in a Ruby app :(

I put my document through yamllint.com and it reformatted the document to this:

--- 
part1: !ruby/object:YAML::Syck::DefaultKey {}

Original comment by Marc.OMo...@swrve.com on 22 May 2014 at 1:16

GoogleCodeExporter commented 9 years ago
I don't see any special mention of '=' in that spec. There is a mention here:

http://www.yaml.org/refcard.html of it being a special default mapping, but I 
don't see that in the 1.1 spec. Can you point me in the right direction please?

Original comment by Marc.OMo...@swrve.com on 22 May 2014 at 1:31

GoogleCodeExporter commented 9 years ago
I see no mention of = in the special characters section:

http://yaml.org/spec/1.1/#id868988

I'm confused. I think this _is_ a valid document, and that snakeyaml should 
parse it.

Original comment by Marc.OMo...@swrve.com on 22 May 2014 at 1:43

GoogleCodeExporter commented 9 years ago
Indeed, the issue for PyYAML stays open for 5 years.
I will have a look.

Original comment by py4fun@gmail.com on 22 May 2014 at 2:55

GoogleCodeExporter commented 9 years ago
I had a look into this today, may attached diff adds a test, and an attempt at 
a fix.

Original comment by Marc.OMo...@swrve.com on 22 May 2014 at 3:01

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for the quick patch. The problem is clear now.
SnakeYAML tries to implement "Value Key Language-Independent Type" 
(http://yaml.org/type/value.html)
Since:
1) it is not done properly (no tests provided)
2) in the YAML 1.2 it is dropped
we can remove this feature to make '=' work as a standard character.
Feel free to test the source or the latest SNAPSHOT.

If other developers do not object this fix will be released in August 2014

Original comment by py4fun@gmail.com on 22 May 2014 at 3:39

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

Original comment by py4fun@gmail.com on 29 May 2014 at 6:55