diff options
author | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2016-01-18 13:16:31 +0200 |
---|---|---|
committer | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2016-01-18 13:30:21 +0200 |
commit | 8fab2f81e3c7bd2630bd53d8c530165808b564c2 (patch) | |
tree | 8c38d5a9864b2f99c480fee3e91c2864daed7a97 /compiler | |
parent | 2309975f782bf59b240e3874d5c31b4b299eca5d (diff) | |
download | Nim-8fab2f81e3c7bd2630bd53d8c530165808b564c2.tar.gz |
Fixed unicode handling in JS. Fixes #3714.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/jsgen.nim | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 14cdf0174..16a03a4ec 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -163,8 +163,26 @@ proc mangleName(s: PSym): Rope = add(result, rope(s.id)) s.loc.r = result +proc escapeJSString(s: string): string = + result = newStringOfCap(s.len + s.len shr 2) + result.add("\"") + for c in items(s): + case c + of '\l': result.add("\\n") + of '\r': result.add("\\r") + of '\t': result.add("\\t") + of '\b': result.add("\\b") + of '\a': result.add("\\a") + of '\e': result.add("\\e") + of '\v': result.add("\\v") + of '\\': result.add("\\\\") + of '\'': result.add("\\'") + of '\"': result.add("\\\"") + else: add(result, c) + result.add("\"") + proc makeJSString(s: string): Rope = - (if s.isNil: "null".rope else: strutils.escape(s).rope) + (if s.isNil: "null".rope else: escapeJSString(s).rope) include jstypes |