mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-14 23:33:28 +00:00
Fix toJSStr for control characters
fixes #4190 Add leading zero to encoded character if it is less than 0x10
This commit is contained in:
committed by
Dmitry Polienko
parent
268f25225a
commit
85c41a1398
@@ -248,8 +248,12 @@ proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} =
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (nonAsciiPart !== null) {
|
||||
var offset = (i - nonAsciiOffset) * 2;
|
||||
var code = `s`[i].toString(16);
|
||||
if (code.length == 1) {
|
||||
code = "0"+code;
|
||||
}
|
||||
nonAsciiPart[offset] = "%";
|
||||
nonAsciiPart[offset + 1] = `s`[i].toString(16);
|
||||
nonAsciiPart[offset + 1] = code;
|
||||
}
|
||||
else if (`s`[i] < 128)
|
||||
asciiPart[i] = fcc(`s`[i]);
|
||||
|
||||
6
tests/js/testtojsstr.nim
Normal file
6
tests/js/testtojsstr.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
discard """
|
||||
output = ""
|
||||
"""
|
||||
|
||||
let s: string = "И\n"
|
||||
let cs = s.cstring
|
||||
Reference in New Issue
Block a user