NeatJSON
NeatJSON copied to clipboard
Bug: Strings containing # sign are escaped unecessarily
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.
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.
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.