Do not leak null characters into the #"" encoding
This commit is contained in:
parent
061898c3c2
commit
200e0a0080
|
@ -1039,7 +1039,11 @@ proc concat[E](result: var string; pr: Preserve[E]) =
|
|||
of pkString:
|
||||
result.add escapeJson(pr.string)
|
||||
of pkByteString:
|
||||
if sequtils.any(pr.bytes, proc (b: byte): bool = b.char in {'\20'..'\21', '#'..'[', ']'..'~'}):
|
||||
if pr.bytes.allIt(char(it) in {' '..'!', '#'..'~'}):
|
||||
result.add("#\"")
|
||||
result.add(cast[string](pr.bytes))
|
||||
result.add('"')
|
||||
else:
|
||||
if pr.bytes.len > 64:
|
||||
result.add("#[") #]#
|
||||
result.add(base64.encode(pr.bytes))
|
||||
|
@ -1051,10 +1055,6 @@ proc concat[E](result: var string; pr: Preserve[E]) =
|
|||
result.add(alphabet[int(b shr 4)])
|
||||
result.add(alphabet[int(b and 0xf)])
|
||||
result.add('"')
|
||||
else:
|
||||
result.add("#\"")
|
||||
result.add(cast[string](pr.bytes))
|
||||
result.add('"')
|
||||
of pkSymbol:
|
||||
result.add(escapeJsonUnquoted(pr.symbol))
|
||||
of pkRecord:
|
||||
|
|
Loading…
Reference in New Issue