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.
This commit is contained in:
parent
ab49197ef1
commit
f893d47b98
|
@ -3611,13 +3611,13 @@ PEG.parser = (function(){
|
||||||
var pos0;
|
var pos0;
|
||||||
|
|
||||||
reportFailures++;
|
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);
|
result0 = input.charAt(pos);
|
||||||
pos++;
|
pos++;
|
||||||
} else {
|
} else {
|
||||||
result0 = null;
|
result0 = null;
|
||||||
if (reportFailures === 0) {
|
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--;
|
reportFailures--;
|
||||||
|
|
22
src/utils.js
22
src/utils.js
|
@ -120,17 +120,21 @@ function quoteForRegexpClass(s) {
|
||||||
/*
|
/*
|
||||||
* Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1.
|
* 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
|
return s
|
||||||
.replace(/\\/g, '\\\\') // backslash
|
.replace(/\\/g, '\\\\') // backslash
|
||||||
.replace(/\0/g, '\\0') // null, IE needs this
|
.replace(/\//g, '\\/') // closing slash
|
||||||
.replace(/\//g, '\\/') // closing slash
|
.replace(/\]/g, '\\]') // closing bracket
|
||||||
.replace(/\]/g, '\\]') // closing bracket
|
.replace(/-/g, '\\-') // dash
|
||||||
.replace(/-/g, '\\-') // dash
|
.replace(/\0/g, '\\0') // null, IE needs this
|
||||||
.replace(/\r/g, '\\r') // carriage return
|
.replace(/\t/g, '\\t') // horizontal tab
|
||||||
.replace(/\n/g, '\\n') // line feed
|
.replace(/\n/g, '\\n') // line feed
|
||||||
.replace(/[\x80-\uFFFF]/g, escape); // non-ASCII characters
|
.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue