From 4b51e6a6d3bbae659d1552a0b75afbdc81b3bdd5 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 16 Apr 2010 08:53:02 +0200 Subject: [PATCH] Quote null characters in regexps, IE does not like them. --- lib/compiler.js | 1 + test/compiler-test.js | 4 ++-- test/metagrammar-test.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 2b82e0b..1972958 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -135,6 +135,7 @@ PEG.RegExpUtils = { /* Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1. */ return s .replace(/\\/g, '\\\\') // backslash + .replace(/\0/g, '\\0') // null, IE needs this .replace(/\//g, '\\/') // closing slash .replace(/]/g, '\\]') // closing bracket .replace(/-/g, '\\-') // dash diff --git a/test/compiler-test.js b/test/compiler-test.js index cd7fbd7..75a6591 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -112,8 +112,8 @@ test("quoteForClass", function() { strictEqual(PEG.RegExpUtils.quoteForClass(""), ''); strictEqual(PEG.RegExpUtils.quoteForClass("abcd"), 'abcd'); strictEqual( - PEG.RegExpUtils.quoteForClass("\\/]-\r\u2028\u2029\n\\/]-\r\u2028\u2029\n"), - '\\\\\\/\\]\\-\\r\\u2028\\u2029\\n\\\\\\/\\]\\-\\r\\u2028\\u2029\\n' + PEG.RegExpUtils.quoteForClass("\\\0/]-\r\u2028\u2029\n\\\0/]-\r\u2028\u2029\n"), + '\\\\\\0\\/\\]\\-\\r\\u2028\\u2029\\n\\\\\\0\\/\\]\\-\\r\\u2028\\u2029\\n' ); }); diff --git a/test/metagrammar-test.js b/test/metagrammar-test.js index 31f7b40..4783f5f 100644 --- a/test/metagrammar-test.js +++ b/test/metagrammar-test.js @@ -299,8 +299,8 @@ with (PEG.Grammar) { test("parses bracketDelimitedCharacter", function() { grammarParserParses("start: [a]", classGrammar("a")); grammarParserParses("start: [\\n]", classGrammar("\\n")); - grammarParserParses("start: [\\0]", classGrammar("\0")); - grammarParserParses("start: [\\x00]", classGrammar("\x00")); + grammarParserParses("start: [\\0]", classGrammar("\\0")); + grammarParserParses("start: [\\x00]", classGrammar("\\0")); grammarParserParses("start: [\\u0120]", classGrammar("\u0120")); grammarParserParses("start: [\\\n]", classGrammar("\\n")); });