From: Jacek Caban Subject: [PATCH 2/2] jscript: Correctly handle empty matches in String.replace Message-Id: <4F8EAA7B.20403@codeweavers.com> Date: Wed, 18 Apr 2012 13:50:19 +0200 --- dlls/jscript/string.c | 3 +++ dlls/jscript/tests/regexp.js | 9 +++++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 17f6c2f..e8b279c 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 c7f9363..d553bb6 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();