From 4733fd062391a2d975771df53cdda058141dbc80 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 20 Apr 2012 11:08:08 +0200 Subject: [PATCH] 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 42e482f28e..6842b58baa 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 d553bb6d6f..7b363dd6b4 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(); -- 2.32.0.93.g670b81a890