Jacek Caban : jscript: Added regexp 'pre-parser' to support non-backslash-sequenced non-terminating '/' in characted classes.

Alexandre Julliard julliard at winehq.org
Fri Apr 20 12:49:27 CDT 2012


Module: wine
Branch: master
Commit: 4733fd062391a2d975771df53cdda058141dbc80
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4733fd062391a2d975771df53cdda058141dbc80

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Apr 20 11:08:08 2012 +0200

jscript: Added regexp 'pre-parser' to support non-backslash-sequenced non-terminating '/' in characted classes.

---

 dlls/jscript/lex.c           |   26 +++++++++++++++++++++-----
 dlls/jscript/tests/regexp.js |    6 ++++++
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c
index 42e482f..6842b58 100644
--- a/dlls/jscript/lex.c
+++ b/dlls/jscript/lex.c
@@ -957,6 +957,7 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
 literal_t *parse_regexp(parser_ctx_t *ctx)
 {
     const WCHAR *re, *flags_ptr;
+    BOOL in_class = FALSE;
     DWORD re_len, flags;
     literal_t *ret;
     HRESULT hres;
@@ -965,14 +966,29 @@ literal_t *parse_regexp(parser_ctx_t *ctx)
 
     while(*--ctx->ptr != '/');
 
+    /* Simple regexp pre-parser; '/' if used in char class does not terminate regexp literal */
     re = ++ctx->ptr;
-    while(ctx->ptr < ctx->end && *ctx->ptr != '/') {
-        if(*ctx->ptr++ == '\\' && ctx->ptr < ctx->end)
-            ctx->ptr++;
+    while(ctx->ptr < ctx->end) {
+        if(*ctx->ptr == '\\') {
+            if(++ctx->ptr == ctx->end)
+                break;
+        }else if(in_class) {
+            if(*ctx->ptr == '\n')
+                break;
+            if(*ctx->ptr == ']')
+                in_class = FALSE;
+        }else {
+            if(*ctx->ptr == '/')
+                break;
+
+            if(*ctx->ptr == '[')
+                in_class = TRUE;
+        }
+        ctx->ptr++;
     }
 
-    if(ctx->ptr == ctx->end) {
-        WARN("unexpected end of file\n");
+    if(ctx->ptr == ctx->end || *ctx->ptr != '/') {
+        WARN("pre-parsing failed\n");
         return NULL;
     }
 
diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js
index d553bb6..7b363dd 100644
--- a/dlls/jscript/tests/regexp.js
+++ b/dlls/jscript/tests/regexp.js
@@ -592,4 +592,10 @@ ok(tmp === "xxx", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
 tmp = "xxx".replace(/^\s*|\s*$/g, "y");
 ok(tmp === "yxxxy", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
 
+tmp = "x/y".replace(/[/]/, "*");
+ok(tmp === "x*y", '"x/y".replace(/[/]/, "*") = ' + tmp);
+
+tmp = "x/y".replace(/[xy/]/g, "*");
+ok(tmp === "***", '"x/y".replace(/[xy/]/, "*") = ' + tmp);
+
 reportSuccess();




More information about the wine-cvs mailing list