From 81f5efe39a6d44d3037dda8bcff01195f5699139 Mon Sep 17 00:00:00 2001 From: Andreas Lind Petersen Date: Sun, 31 Mar 2013 11:07:31 +0200 Subject: [PATCH] Output, to_ascii: Escape non-ascii chars with \xnn instead of \unnnn whenever possible. --- lib/output.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/output.js b/lib/output.js index 42b3aad9..b99bfa63 100644 --- a/lib/output.js +++ b/lib/output.js @@ -72,8 +72,13 @@ function OutputStream(options) { function to_ascii(str) { return str.replace(/[\u0080-\uffff]/g, function(ch) { var code = ch.charCodeAt(0).toString(16); - while (code.length < 4) code = "0" + code; - return "\\u" + code; + if (code.length <= 2) { + while (code.length < 2) code = "0" + code; + return "\\x" + code; + } else { + while (code.length < 4) code = "0" + code; + return "\\u" + code; + } }); }; -- 2.34.1