Commit 1c3e0dd3 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

jscript: Properly handle \0 characters in String indexOf method.

parent 54e67360
......@@ -486,9 +486,9 @@ static HRESULT String_fontsize(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
unsigned pos = 0, search_len, length;
jsstr_t *search_jsstr, *jsstr;
const WCHAR *search_str, *str;
int length, pos = 0;
INT ret = -1;
HRESULT hres;
......@@ -498,7 +498,6 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(FAILED(hres))
return hres;
length = jsstr_length(jsstr);
if(!argc) {
if(r)
*r = jsval_number(-1);
......@@ -512,6 +511,9 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return hres;
}
search_len = jsstr_length(search_jsstr);
length = jsstr_length(jsstr);
if(argc >= 2) {
double d;
......@@ -520,14 +522,16 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
pos = is_int32(d) ? min(length, d) : length;
}
if(SUCCEEDED(hres)) {
if(SUCCEEDED(hres) && length >= search_len) {
const WCHAR *end = str+length-search_len;
const WCHAR *ptr;
ptr = strstrW(str+pos, search_str);
if(ptr)
ret = ptr - str;
else
ret = -1;
for(ptr = str+pos; ptr <= end; ptr++) {
if(!memcmp(ptr, search_str, search_len*sizeof(WCHAR))) {
ret = ptr-str;
break;
}
}
}
jsstr_release(search_jsstr);
......
......@@ -629,6 +629,12 @@ tmp = "abcd".indexOf();
ok(tmp == -1, "indexOf = " + tmp);
tmp = "abcd".indexOf("b", bigInt);
ok(tmp == -1, "indexOf = " + tmp);
tmp = "abcd".indexOf("abcd",0);
ok(tmp === 0, "indexOf = " + tmp);
tmp = "abcd".indexOf("abcd",1);
ok(tmp === -1, "indexOf = " + tmp);
tmp = ("ab" + String.fromCharCode(0) + "cd").indexOf(String.fromCharCode(0));
ok(tmp === 2, "indexOf = " + tmp);
tmp = "abcd".lastIndexOf("bc",1);
ok(tmp === 1, "lastIndexOf = " + tmp);
......@@ -650,6 +656,12 @@ tmp = strObj.lastIndexOf("b");
ok(tmp === 1, "lastIndexOf = " + tmp);
tmp = "bbb".lastIndexOf("b", bigInt);
ok(tmp === 2, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("abcd",4);
ok(tmp === 0, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("abcd",0);
ok(tmp === 0, "lastIndexOf = " + tmp);
tmp = ("ab" + String.fromCharCode(0) + "cd").lastIndexOf(String.fromCharCode(0));
ok(tmp === 2, "lastIndexOf = " + tmp);
tmp = "".toLowerCase();
ok(tmp === "", "''.toLowerCase() = " + tmp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment