NeatJSON icon indicating copy to clipboard operation
NeatJSON copied to clipboard

Bug: Strings containing # sign are escaped unecessarily

Open flyinbutrs opened this issue 8 years ago • 2 comments

Input:

["#{test}"]

Pry log of failure:

[1] pry(main)> require 'neatjson'
true
[2] pry(main)> test = JSON.parse(File.open('test.json').read)
[
  [0] "\#{test}"
]
[3] pry(main)> puts test.to_json
["#{test}"]
nil
[4] pry(main)> puts JSON.neat_generate(test)
["\#{test}"]
nil

When outputting the test file with native to_json, the # isn't escaped. When outputting using neat_generate, it is.

flyinbutrs avatar May 19 '16 03:05 flyinbutrs

Fun bug! Of course the backslash does not affect the functionality, but it is foolish and unnecessary. The offending line is:

when String,Integer       then "#{indent}#{o.inspect}"

I'll have to treat Strings with a better escaping mechanism that does only the minimum necessary. Thanks for the report.

Phrogz avatar May 20 '16 05:05 Phrogz

If I have a JSON like the following:

{
    "name": "\#channel"
}

I will get an invalid JSON. Refer to https://jsonlint.com/, and such JSON files cannot be parsed if you try to read them.

quintuschen avatar Dec 04 '18 00:12 quintuschen