Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong YAML nil serialization and scalars deserialization #4175

Closed
olbat opened this issue Mar 22, 2017 · 6 comments
Closed

Wrong YAML nil serialization and scalars deserialization #4175

olbat opened this issue Mar 22, 2017 · 6 comments

Comments

@olbat
Copy link
Contributor

olbat commented Mar 22, 2017

Crystal's YAML builder/parser does not handle properly nil serialization and YAML scalars deserialization:

Here is an example:

$ cat test.cr
require "yaml"
p "".to_yaml
p [""].to_yaml
p({"a" => ""}.to_yaml)
p YAML.parse("---")
p YAML.parse("~")
p YAML.parse("null")
p YAML.parse("- ")
p YAML.parse("a: ")
p YAML.parse("true")
p YAML.parse("yes")
p YAML.parse("on")
p YAML.parse(".inf")
p YAML.parse(".nan")
p YAML.parse("01:01")
p YAML.parse("1970-01-01")

the output:

$ crystal run test.cr | nl
     1	"--- \n...\n"
     2	"---\n- \n"
     3	"---\na: \n"
     4	""
     5	"~"
     6	"null"
     7	[""]
     8	{"a" => ""}
     9	"true"
    10	"yes"
    11	"on"
    12	".inf"
    13	".nan"
    14	"01:01"
    15	"1970-01-01"

$ crystal --version
Crystal 0.21.1 [3c6c75e] (2017-03-06) LLVM 3.5.0

to compare, the output of Ruby's implementation:

$ sed 's/parse/load/' test.cr | ruby | nl
     1	"--- ''\n"
     2	"---\n- ''\n"
     3	"---\na: ''\n"
     4	nil
     5	nil
     6	nil
     7	[nil]
     8	{"a"=>nil}
     9	true
    10	true
    11	true
    12	Infinity
    13	NaN
    14	3660
    15	#<Date: 1970-01-01 ((2440588j,0s,0n),+0s,2299161j)>

$ ruby --version
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]

edit: deserialization of every YAML scalars seems to be impacted

@olbat
Copy link
Contributor Author

olbat commented Mar 22, 2017

I'm not sure it will be useful to fix the issue but here is the Ruby's Psych scalar scanner implementation.

@olbat olbat changed the title Wrong YAML (de)serialization of nil and empty strings Wrong YAML nil serialization and scalars deserialization Mar 23, 2017
@asterite
Copy link
Member

This is more or less a duplicate of #4175 . The current YAML parser only knows about String, Array and Hash. We need to extend this to support the core YAML schema, possibly other schemas too.

@refi64
Copy link
Contributor

refi64 commented Mar 23, 2017

@asterite Did you mean #2873 or #3101? Right now, your link is giving me a recursion error...

@olbat
Copy link
Contributor Author

olbat commented Mar 23, 2017

Oops, I tried to find a related issue but I missed both of them, thanks for the references.

@straight-shoota
Copy link
Member

This issue can't possibly be a duplicate of itself and I don't think it is a duplicate of #2873 or #3101 either. Please reopen.

@ysbaddaden
Copy link
Contributor

No. It's a duplicate of #3101 per "unsupported types (e.g. null, numbers)".

@ysbaddaden ysbaddaden marked this as a duplicate of #3101 Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants