JuliaIO / JSON.jl

JSON parsing and printing
Other
312 stars 101 forks source link

Parsing control characters such as newline should be invalid #127

Closed dreammaker closed 8 years ago

dreammaker commented 9 years ago

Parsing a newline character in a string should be an error, according to the standard and the parsers in basically all other languages. Using JSON 0.4.6 I get this:

julia> JSON.parse("\"\n\"")
"\n"

This has caused us some problems. We thought our JSON was valid since the Julia JSON package parsed it, but it hasn't been.

stevengj commented 9 years ago

Should be a straightforward change to the parse_string function (https://github.com/JuliaLang/JSON.jl/blob/fe9de2d226619ea52510479bc30b9acaad77628d/src/Parser.jl#L142). What characters exactly does the standard permit?

IainNZ commented 9 years ago

http://www.json.org/ suggests "anything but control characters, ", and \"

StefanKarpinski commented 9 years ago

Which suggests that JSON is actually doing this right. It seems unreasonable for the package to refuse any syntax that any JSON parser anywhere happens to refuse.

StefanKarpinski commented 9 years ago

Oh, does a literal newline count as a control character? In that case, I guess this should be an error.

ScottPJones commented 9 years ago

The ECMA standard is a lot clearer: All characters may be placed within the quotation marks except for the characters that must be escaped: quotation mark (U+0022), reverse solidus (U+005C), and the control characters U+0000 to U+001F

TotalVerb commented 8 years ago

This is definitely fixed by #140, but I messed up the autoclose so GitHub did not close it. Good to close? @dreammaker @kmsquire

dreammaker commented 8 years ago

Closed by #140.