Quote null characters in regexps, IE does not like them.

redux
David Majda 15 years ago
parent 7fc491412d
commit 4b51e6a6d3

@ -135,6 +135,7 @@ PEG.RegExpUtils = {
/* Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1. */ /* Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1. */
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

@ -112,8 +112,8 @@ test("quoteForClass", function() {
strictEqual(PEG.RegExpUtils.quoteForClass(""), ''); strictEqual(PEG.RegExpUtils.quoteForClass(""), '');
strictEqual(PEG.RegExpUtils.quoteForClass("abcd"), 'abcd'); strictEqual(PEG.RegExpUtils.quoteForClass("abcd"), 'abcd');
strictEqual( strictEqual(
PEG.RegExpUtils.quoteForClass("\\/]-\r\u2028\u2029\n\\/]-\r\u2028\u2029\n"), PEG.RegExpUtils.quoteForClass("\\\0/]-\r\u2028\u2029\n\\\0/]-\r\u2028\u2029\n"),
'\\\\\\/\\]\\-\\r\\u2028\\u2029\\n\\\\\\/\\]\\-\\r\\u2028\\u2029\\n' '\\\\\\0\\/\\]\\-\\r\\u2028\\u2029\\n\\\\\\0\\/\\]\\-\\r\\u2028\\u2029\\n'
); );
}); });

@ -299,8 +299,8 @@ with (PEG.Grammar) {
test("parses bracketDelimitedCharacter", function() { test("parses bracketDelimitedCharacter", function() {
grammarParserParses("start: [a]", classGrammar("a")); grammarParserParses("start: [a]", classGrammar("a"));
grammarParserParses("start: [\\n]", classGrammar("\\n")); grammarParserParses("start: [\\n]", classGrammar("\\n"));
grammarParserParses("start: [\\0]", classGrammar("\0")); grammarParserParses("start: [\\0]", classGrammar("\\0"));
grammarParserParses("start: [\\x00]", classGrammar("\x00")); grammarParserParses("start: [\\x00]", classGrammar("\\0"));
grammarParserParses("start: [\\u0120]", classGrammar("\u0120")); grammarParserParses("start: [\\u0120]", classGrammar("\u0120"));
grammarParserParses("start: [\\\n]", classGrammar("\\n")); grammarParserParses("start: [\\\n]", classGrammar("\\n"));
}); });

Loading…
Cancel
Save