* fix #7881, control characters in json output * Add test for control characters in json
This commit is contained in:
parent
66780c1f4f
commit
5866e64ebc
1 changed files with 3 additions and 0 deletions
|
|
@ -558,6 +558,8 @@ proc escapeJson*(s: string; result: var string) =
|
||||||
of '\t': result.add("\\t")
|
of '\t': result.add("\\t")
|
||||||
of '\r': result.add("\\r")
|
of '\r': result.add("\\r")
|
||||||
of '"': result.add("\\\"")
|
of '"': result.add("\\\"")
|
||||||
|
of '\0'..'\7': result.add("\\u000" & $ord(c))
|
||||||
|
of '\14'..'\31': result.add("\\u00" & $ord(c))
|
||||||
of '\\': result.add("\\\\")
|
of '\\': result.add("\\\\")
|
||||||
else: result.add(c)
|
else: result.add(c)
|
||||||
result.add("\"")
|
result.add("\"")
|
||||||
|
|
@ -1581,6 +1583,7 @@ when isMainModule:
|
||||||
doAssert(parsed2{"repository", "description"}.str=="IRC Library for Haskell", "Couldn't fetch via multiply nested key using {}")
|
doAssert(parsed2{"repository", "description"}.str=="IRC Library for Haskell", "Couldn't fetch via multiply nested key using {}")
|
||||||
|
|
||||||
doAssert escapeJson("\10Foo🎃barÄ") == "\"\\nFoo🎃barÄ\""
|
doAssert escapeJson("\10Foo🎃barÄ") == "\"\\nFoo🎃barÄ\""
|
||||||
|
doAssert escapeJson("\0\7\20") == "\"\\u0000\\u0007\\u0020\"" # for #7887
|
||||||
|
|
||||||
# Test with extra data
|
# Test with extra data
|
||||||
when not defined(js):
|
when not defined(js):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue