From 062c6ae706d4307de2555a8a6acf9d6a7204d274 Mon Sep 17 00:00:00 2001 From: David Majda Date: Thu, 1 Sep 2016 15:20:33 +0200 Subject: [PATCH] Escape backspace in regexp classes as "\b", not "\x08" The "\x08" escaping is necessary only outside of classes (where "\b" means "word boundary"). --- lib/compiler/js.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/compiler/js.js b/lib/compiler/js.js index 1b63d26..07f5ab0 100644 --- a/lib/compiler/js.js +++ b/lib/compiler/js.js @@ -36,17 +36,18 @@ var js = { * For portability, we also escape all control and non-ASCII characters. */ return s - .replace(/\\/g, '\\\\') // backslash - .replace(/\//g, '\\/') // closing slash - .replace(/\]/g, '\\]') // closing bracket - .replace(/\^/g, '\\^') // caret - .replace(/-/g, '\\-') // dash - .replace(/\0/g, '\\0') // null - .replace(/\t/g, '\\t') // horizontal tab - .replace(/\n/g, '\\n') // line feed - .replace(/\v/g, '\\v') // vertical tab - .replace(/\f/g, '\\f') // form feed - .replace(/\r/g, '\\r') // carriage return + .replace(/\\/g, '\\\\') // backslash + .replace(/\//g, '\\/') // closing slash + .replace(/\]/g, '\\]') // closing bracket + .replace(/\^/g, '\\^') // caret + .replace(/-/g, '\\-') // dash + .replace(/\0/g, '\\0') // null + .replace(/\x08/g, '\\b') // backspace + .replace(/\t/g, '\\t') // horizontal tab + .replace(/\n/g, '\\n') // line feed + .replace(/\v/g, '\\v') // vertical tab + .replace(/\f/g, '\\f') // form feed + .replace(/\r/g, '\\r') // carriage return .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\xFF]/g, function(ch) { return '\\x' + hex(ch); }) .replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })