shithub: libmujs

Download patch

ref: 15795e2b58fcb6e801c401795d40c1344517b5ee
parent: 8a659b28210220f6e29d5ed671e2c22adde9a7c1
author: Tor Andersson <[email protected]>
date: Thu Oct 9 11:18:26 EDT 2014

Allow unescaped / inside classes in regular expression tokens.

--- a/jslex.c
+++ b/jslex.c
@@ -454,6 +454,7 @@
 {
 	const char *s;
 	int g, m, i;
+	int inclass = 0;
 
 	/* already consumed initial '/' */
 
@@ -460,7 +461,7 @@
 	textinit(J);
 
 	/* regexp body */
-	while (PEEK != '/') {
+	while (PEEK != '/' || inclass) {
 		if (PEEK == 0 || PEEK == '\n') {
 			jsY_error(J, "regular expression not terminated");
 		} else if (ACCEPT('\\')) {
@@ -474,6 +475,10 @@
 				NEXT();
 			}
 		} else {
+			if (PEEK == '[' && !inclass)
+				inclass = 1;
+			if (PEEK == ']' && inclass)
+				inclass = 0;
 			textpush(J, PEEK);
 			NEXT();
 		}