Skip to content

Commit b65fd6a

Browse files
Fix missing escaping of backslashes in writing string value (#132)
* Fix missing escaping of backslashes in writing string value * added test of backslash escaping Fixes: waku-org/nwaku#3572
1 parent 0640259 commit b65fd6a

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

json_serialization/writer.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ template writeValueStringLike(w, value) =
459459
of '\f': addPrefixSlash 'f' # \x0c
460460
of '\r': addPrefixSlash 'r' # \x0d
461461
of '"' : addPrefixSlash '\"'
462+
of '\\': addPrefixSlash '\\'
462463
of '\x00'..'\x07', '\x0b', '\x0e'..'\x1f':
463464
s.write "\\u00"
464465
s.write hexChars[(uint8(c) shr 4) and 0x0f]

tests/test_writer.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ suite "Test writer":
293293

294294
test "escapes":
295295
check Json.encode("\x12") == """"\u0012""""
296+
check Json.encode("""a\b""") == """"a\\b""""
296297

297298
test "Empty object":
298299
type NoFields = object

0 commit comments

Comments
 (0)