mirror of
https://github.com/reactos/wine.git
synced 2024-11-24 20:30:01 +00:00
jscript: Added regexp 'pre-parser' to support non-backslash-sequenced non-terminating '/' in characted classes.
This commit is contained in:
parent
a7137ef035
commit
4733fd0623
@ -957,6 +957,7 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
|
|||||||
literal_t *parse_regexp(parser_ctx_t *ctx)
|
literal_t *parse_regexp(parser_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
const WCHAR *re, *flags_ptr;
|
const WCHAR *re, *flags_ptr;
|
||||||
|
BOOL in_class = FALSE;
|
||||||
DWORD re_len, flags;
|
DWORD re_len, flags;
|
||||||
literal_t *ret;
|
literal_t *ret;
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
@ -965,14 +966,29 @@ literal_t *parse_regexp(parser_ctx_t *ctx)
|
|||||||
|
|
||||||
while(*--ctx->ptr != '/');
|
while(*--ctx->ptr != '/');
|
||||||
|
|
||||||
|
/* Simple regexp pre-parser; '/' if used in char class does not terminate regexp literal */
|
||||||
re = ++ctx->ptr;
|
re = ++ctx->ptr;
|
||||||
while(ctx->ptr < ctx->end && *ctx->ptr != '/') {
|
while(ctx->ptr < ctx->end) {
|
||||||
if(*ctx->ptr++ == '\\' && ctx->ptr < ctx->end)
|
if(*ctx->ptr == '\\') {
|
||||||
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) {
|
if(ctx->ptr == ctx->end || *ctx->ptr != '/') {
|
||||||
WARN("unexpected end of file\n");
|
WARN("pre-parsing failed\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,4 +592,10 @@ ok(tmp === "xxx", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
|
|||||||
tmp = "xxx".replace(/^\s*|\s*$/g, "y");
|
tmp = "xxx".replace(/^\s*|\s*$/g, "y");
|
||||||
ok(tmp === "yxxxy", '"xxx".replace(/^\s*|\s*$/g, "y") = ' + tmp);
|
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();
|
reportSuccess();
|
||||||
|
Loading…
Reference in New Issue
Block a user