diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-06-18 12:07:14 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-06-18 12:07:14 +0200 |
commit | 7131d6231d60cd24778bb52a740abc3ee95a7531 (patch) | |
tree | 34426d2833fb4a1078d8f0eac9ffd6796a9869aa | |
parent | ef762c6ef09e7e028e980034a0833de4d0a1227c (diff) | |
parent | 50d2d54fb0799def08c2dcb42b64989d7b7bcfa8 (diff) | |
download | Nim-7131d6231d60cd24778bb52a740abc3ee95a7531.tar.gz |
Merge pull request #2947 from yglukhov/fix-fix-2917
Fixed fix of #2917
-rw-r--r-- | lib/system/jssys.nim | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 82cf18299..242f42c16 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -178,15 +178,18 @@ proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} = var asciiPart = new Array(len); var fcc = String.fromCharCode; var nonAsciiPart = null; + var nonAsciiOffset = 0; for (var i = 0; i < len; ++i) { if (nonAsciiPart !== null) { - nonAsciiPart[i * 2] = "%"; - nonAsciiPart[i * 2 + 1] = `s`[i].toString(16); + var offset = (i - nonAsciiOffset) * 2; + nonAsciiPart[offset] = "%"; + nonAsciiPart[offset + 1] = `s`[i].toString(16); } else if (`s`[i] < 128) asciiPart[i] = fcc(`s`[i]); else { asciiPart.length = i; + nonAsciiOffset = i; nonAsciiPart = new Array((len - i) * 2); --i; } |