cuizhennan / snakeyaml

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

Key's do not get ' symbols when saving, if they contain a :, causing invalid YAML. #176

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile this code http://pastebin.com/EG08zJLG
2. Run the code
3. Look inside test.yml, the key steak:cow doesn't have a ' around it.

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

I expect the key to automatically get 's around it. However, it doesn't. 
Causing the YAML to parse cow as the value, not 11

What version of SnakeYAML are you using? On what Java version?
1.12, but occurs on latest snapshot of 1.13 also.
Java 7

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

None that I know of.

Original issue reported on code.google.com by mnmill...@gmail.com on 5 May 2013 at 12:01

Attachments:

GoogleCodeExporter commented 9 years ago
May I also add, that if I put 's into the key before saving it. The output 
result is '''steak:cow''': '11'

Original comment by mnmill...@gmail.com on 5 May 2013 at 12:05

GoogleCodeExporter commented 9 years ago
The last question asks YOU to provide us with a failing test (which is the best 
way to describe the problem)
I tried to create a test myself out of your code:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue176/SingleQuoteTest.java

I do not see any problem here. Feel free to change the test to identify your 
expectations.

If you think single quotes are missing, can you please explain why do you 
expect to see single quotes ?

Original comment by py4fun@gmail.com on 5 May 2013 at 2:32

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
By the way.
This YAML is valid:
cows:
    steak:cow: '11'

this is its canonical form:
%YAML 1.1
---
!!map {
    ? !!str "cows"
    : !!map {
        ? !!str "steak:cow"
        : !!str "11",
    },
}
...

The colon (:) is not allowed in plain scalars in flow mode. But you have 
explicitly set block mode in the code. Try to remove this settings and you will 
get:

cows: {'steak:cow': '11'}

Original comment by py4fun@gmail.com on 5 May 2013 at 3:59

GoogleCodeExporter commented 9 years ago
I say it's invalid because when I read it, I get "11", not "cow".

Original comment by mnmill...@gmail.com on 5 May 2013 at 7:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Indeed '11' is the value, 'cow' is a part of the key.
As you can see a failing test is the best way to show the problem. Can you 
please attach a test ?

Original comment by py4fun@gmail.com on 5 May 2013 at 10:20

GoogleCodeExporter commented 9 years ago
What more can I provide to this issue?

I store the key steak:cow, but I do not get 11 if I use that key, but cow:11

However, if I use steak as the key, I get cow also.

Original comment by mnmill...@gmail.com on 11 May 2013 at 9:33

GoogleCodeExporter commented 9 years ago
Oh, a test case.

Sure, I'll make one as soon as I can.

Original comment by mnmill...@gmail.com on 11 May 2013 at 9:34

GoogleCodeExporter commented 9 years ago
http://pastebin.com/Yktm3x6n

That now contains a test case, that fails.

Original comment by mnmill...@gmail.com on 12 May 2013 at 2:20

GoogleCodeExporter commented 9 years ago
Well, the test you have provided works properly for me.

1) what is the exact environment ? (the JDK version, the OS version)
2) what do you get if you run the tests which I have extracted from your file ? 
(http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeya
ml/issues/issue176/SingleQuoteTest.java) Does the whole test suite work for you 
?

Original comment by py4fun@gmail.com on 12 May 2013 at 8:02

GoogleCodeExporter commented 9 years ago
After running the test again, it works fine. No idea what was going wrong that 
time or earlier.

Original comment by mnmill...@gmail.com on 15 May 2013 at 9:46

GoogleCodeExporter commented 9 years ago
I think this issue is the prove that a report without a failing test should not 
be accepted. We could have won a week if the test is provided in the very 
beginning.
(it is still unclear why to wait a few days to answer with one sentence...)

Original comment by py4fun@gmail.com on 16 May 2013 at 4:21