diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c index 42e482f28e9..6842b58baa6 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 d553bb6d6f4..7b363dd6b44 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();