From c1cb8f29b022ca1a1cf9da560f70d4b83337a9de Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 18 Apr 2012 13:50:19 +0200 Subject: [PATCH] jscript: Correctly handle empty matches in String.replace. --- dlls/jscript/string.c | 3 +++ dlls/jscript/tests/regexp.js | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 17f6c2f42f2..e8b279c197c 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -868,6 +868,9 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI } if(FAILED(hres)) break; + + if(!match.len) + cp++; }else { match.str = strstrW(cp, match_str); if(!match.str) diff --git a/dlls/jscript/tests/regexp.js b/dlls/jscript/tests/regexp.js index c7f93639cb1..d553bb6d6f4 100644 --- a/dlls/jscript/tests/regexp.js +++ b/dlls/jscript/tests/regexp.js @@ -583,4 +583,13 @@ ok(i === null, "' undefined '.search() = " + i); tmp = "=)".replace(/=/, "?"); ok(tmp === "?)", "'=)'.replace(/=/, '?') = " + tmp); +tmp = " ".replace(/^\s*|\s*$/g, "y"); +ok(tmp === "yy", '" ".replace(/^\s*|\s*$/g, "y") = ' + tmp); + +tmp = "xxx".replace(/^\s*|\s*$/g, ""); +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); + reportSuccess(); -- 2.11.4.GIT