Merge pull request #4191 from nigredo-tori/fix_tojsstr
Fix toJSStr for control characters
This commit is contained in:
commit
ec7d556c20
2 changed files with 13 additions and 1 deletions
|
|
@ -248,8 +248,12 @@ proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} =
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
if (nonAsciiPart !== null) {
|
if (nonAsciiPart !== null) {
|
||||||
var offset = (i - nonAsciiOffset) * 2;
|
var offset = (i - nonAsciiOffset) * 2;
|
||||||
|
var code = `s`[i].toString(16);
|
||||||
|
if (code.length == 1) {
|
||||||
|
code = "0"+code;
|
||||||
|
}
|
||||||
nonAsciiPart[offset] = "%";
|
nonAsciiPart[offset] = "%";
|
||||||
nonAsciiPart[offset + 1] = `s`[i].toString(16);
|
nonAsciiPart[offset + 1] = code;
|
||||||
}
|
}
|
||||||
else if (`s`[i] < 128)
|
else if (`s`[i] < 128)
|
||||||
asciiPart[i] = fcc(`s`[i]);
|
asciiPart[i] = fcc(`s`[i]);
|
||||||
|
|
|
||||||
8
tests/js/testtojsstr.nim
Normal file
8
tests/js/testtojsstr.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
output = "И\n"
|
||||||
|
"""
|
||||||
|
|
||||||
|
let s: string = "И\n"
|
||||||
|
let cs = s.cstring
|
||||||
|
|
||||||
|
echo $s
|
||||||
Loading…
Add table
Add a link
Reference in a new issue