Module: wine Branch: master Commit: c1cb8f29b022ca1a1cf9da560f70d4b83337a9de URL: http://source.winehq.org/git/wine.git/?a=commit;h=c1cb8f29b022ca1a1cf9da560f...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Apr 18 13:50:19 2012 +0200
jscript: Correctly handle empty matches in String.replace.
---
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();