From 1988110a284678a7068ed90eaef138371b619f44 Mon Sep 17 00:00:00 2001 From: David Majda Date: Wed, 21 Nov 2012 08:24:08 +0100 Subject: [PATCH] Fix code generated for classes starting with "\^" Before this commit, incorrect regexps were produced for classes starting with "\^". For example, this grammar: start = [\^a] didn't match "a" because the generated regexp inside the parser was /^[^a]/, not /^[\^a]/ as it should be. This commit fixes the issue by escaping "^" in |quoteForRegexpClass|. Fixes GH-125. --- lib/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils.js b/lib/utils.js index 564dedc..358bf0c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -183,6 +183,7 @@ var utils = { .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