From f893d47b986450546c84f2d7048053c6be85d4cf Mon Sep 17 00:00:00 2001 From: David Majda Date: Wed, 14 Sep 2011 11:35:40 +0200 Subject: [PATCH] src/utils.js: Make |quoteForRegexpClass| escape control characters Fixes the following JSHint errors: ./src/parser.js: line 3614, col 16, Mixed spaces and tabs. ./src/parser.js: line 3614, col 20, Unsafe character. --- src/parser.js | 4 ++-- src/utils.js | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/parser.js b/src/parser.js index 91ce674..efafb7c 100644 --- a/src/parser.js +++ b/src/parser.js @@ -3611,13 +3611,13 @@ PEG.parser = (function(){ var pos0; reportFailures++; - if (/^[ \xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/.test(input.charAt(pos))) { + if (/^[ \t\x0B\f\xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { result0 = null; if (reportFailures === 0) { - matchFailed("[ \t\x0B\f\\xA0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"); + matchFailed("[ \\t\\x0B\\f\\xA0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"); } } reportFailures--; diff --git a/src/utils.js b/src/utils.js index fc04a4d..3ab215c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -120,17 +120,21 @@ function quoteForRegexpClass(s) { /* * Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1. * - * For portability, we also escape escape all non-ASCII characters. + * For portability, we also escape escape all control and non-ASCII + * characters. */ return s - .replace(/\\/g, '\\\\') // backslash - .replace(/\0/g, '\\0') // null, IE needs this - .replace(/\//g, '\\/') // closing slash - .replace(/\]/g, '\\]') // closing bracket - .replace(/-/g, '\\-') // dash - .replace(/\r/g, '\\r') // carriage return - .replace(/\n/g, '\\n') // line feed - .replace(/[\x80-\uFFFF]/g, escape); // non-ASCII characters + .replace(/\\/g, '\\\\') // backslash + .replace(/\//g, '\\/') // closing slash + .replace(/\]/g, '\\]') // closing bracket + .replace(/-/g, '\\-') // dash + .replace(/\0/g, '\\0') // null, IE needs this + .replace(/\t/g, '\\t') // horizontal tab + .replace(/\n/g, '\\n') // line feed + .replace(/\v/g, '\\x0B') // vertical tab + .replace(/\f/g, '\\f') // form feed + .replace(/\r/g, '\\r') // carriage return + .replace(/[\x01-\x08\x0E-\x1F\x80-\uFFFF]/g, escape); } /*