Jacek Caban : vbscript: Treat empty regexp pattern the same way as NULL pattern.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Jun 29 08:12:10 CDT 2015
Module: wine
Branch: master
Commit: 392736c5e8f7b5b23240cbe48879a168550c3d74
URL: http://source.winehq.org/git/wine.git/?a=commit;h=392736c5e8f7b5b23240cbe48879a168550c3d74
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Jun 29 11:55:56 2015 +0200
vbscript: Treat empty regexp pattern the same way as NULL pattern.
---
dlls/vbscript/tests/regexp.vbs | 17 +++++++++++++++++
dlls/vbscript/vbregexp.c | 28 +++++++++++-----------------
2 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/dlls/vbscript/tests/regexp.vbs b/dlls/vbscript/tests/regexp.vbs
index 0354fb7..834be21 100644
--- a/dlls/vbscript/tests/regexp.vbs
+++ b/dlls/vbscript/tests/regexp.vbs
@@ -174,4 +174,21 @@ Call ok(x.IgnoreCase = false, "RegExp.IgnoreCase = " & x.IgnoreCase)
Call ok(x.Global = false, "RegExp.Global = " & x.Global)
Call ok(x.Multiline = false, "RegExp.Multiline = " & x.Multiline)
+set matches = x.execute("test")
+Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
+x.pattern = ""
+set matches = x.execute("test")
+Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
+set match = matches.item(0)
+Call ok(match.Value = "", "match.Value = " & match.Value)
+x.global = true
+set matches = x.execute("test")
+Call ok(matches.Count = 5, "matches.Count = " & matches.Count)
+set match = matches.item(0)
+Call ok(match.Value = "", "match.Value = " & match.Value)
+set match = matches.item(4)
+Call ok(match.Value = "", "match.Value = " & match.Value)
+matches = x.test("test")
+Call ok(matches = true, "matches = " & matches)
+
Call reportSuccess()
diff --git a/dlls/vbscript/vbregexp.c b/dlls/vbscript/vbregexp.c
index 0a399b9..800ea5e 100644
--- a/dlls/vbscript/vbregexp.c
+++ b/dlls/vbscript/vbregexp.c
@@ -1189,29 +1189,23 @@ static HRESULT WINAPI RegExp2_get_Pattern(IRegExp2 *iface, BSTR *pPattern)
static HRESULT WINAPI RegExp2_put_Pattern(IRegExp2 *iface, BSTR pattern)
{
RegExp2 *This = impl_from_IRegExp2(iface);
- WCHAR *p;
- DWORD size;
+ WCHAR *new_pattern;
TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(pattern));
- if(!pattern) {
- heap_free(This->pattern);
- if(This->regexp) {
- regexp_destroy(This->regexp);
- This->regexp = NULL;
- }
- This->pattern = NULL;
- return S_OK;
+ if(pattern && *pattern) {
+ SIZE_T size = (SysStringLen(pattern)+1) * sizeof(WCHAR);
+ new_pattern = heap_alloc(size);
+ if(!new_pattern)
+ return E_OUTOFMEMORY;
+ memcpy(new_pattern, pattern, size);
+ }else {
+ new_pattern = NULL;
}
- size = (SysStringLen(pattern)+1) * sizeof(WCHAR);
- p = heap_alloc(size);
- if(!p)
- return E_OUTOFMEMORY;
-
heap_free(This->pattern);
- This->pattern = p;
- memcpy(p, pattern, size);
+ This->pattern = new_pattern;
+
if(This->regexp) {
regexp_destroy(This->regexp);
This->regexp = NULL;
More information about the wine-cvs
mailing list