mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 05:23:20 +00:00
Use hexadecimal in json escaping (#10437) [backport]
(cherry picked from commit 8313e5f24e)
This commit is contained in:
committed by
narimiran
parent
818b23ce7b
commit
2853aeda8e
@@ -603,7 +603,7 @@ proc escapeJsonUnquoted*(s: string; result: var string) =
|
||||
of '\r': result.add("\\r")
|
||||
of '"': result.add("\\\"")
|
||||
of '\0'..'\7': result.add("\\u000" & $ord(c))
|
||||
of '\14'..'\31': result.add("\\u00" & $ord(c))
|
||||
of '\14'..'\31': result.add("\\u00" & toHex(ord(c), 2))
|
||||
of '\\': result.add("\\\\")
|
||||
else: result.add(c)
|
||||
|
||||
@@ -1664,9 +1664,9 @@ when isMainModule:
|
||||
doAssert(parsed2{"repository", "description"}.str=="IRC Library for Haskell", "Couldn't fetch via multiply nested key using {}")
|
||||
|
||||
doAssert escapeJsonUnquoted("\10Foo🎃barÄ") == "\\nFoo🎃barÄ"
|
||||
doAssert escapeJsonUnquoted("\0\7\20") == "\\u0000\\u0007\\u0020" # for #7887
|
||||
doAssert escapeJsonUnquoted("\0\7\20") == "\\u0000\\u0007\\u0014" # for #7887
|
||||
doAssert escapeJson("\10Foo🎃barÄ") == "\"\\nFoo🎃barÄ\""
|
||||
doAssert escapeJson("\0\7\20") == "\"\\u0000\\u0007\\u0020\"" # for #7887
|
||||
doAssert escapeJson("\0\7\20") == "\"\\u0000\\u0007\\u0014\"" # for #7887
|
||||
|
||||
# Test with extra data
|
||||
when not defined(js):
|
||||
|
||||
Reference in New Issue
Block a user