From: Jacek Caban Subject: [PATCH 3/3] mshtml: Rewrite IHTMLLocation::get_pathname on top of IUri. Message-Id: Date: Tue, 28 May 2019 17:33:58 +0200 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=37279 Signed-off-by: Jacek Caban --- dlls/mshtml/htmllocation.c | 23 +++++++++++++---------- dlls/mshtml/tests/elements.js | 17 +++++++++++++++++ dlls/mshtml/tests/htmllocation.c | 3 +++ dlls/mshtml/tests/script.c | 6 ++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/dlls/mshtml/htmllocation.c b/dlls/mshtml/htmllocation.c index 4b8a07a6e6..06cf7e173a 100644 --- a/dlls/mshtml/htmllocation.c +++ b/dlls/mshtml/htmllocation.c @@ -459,7 +459,8 @@ static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v) static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p) { HTMLLocation *This = impl_from_IHTMLLocation(iface); - URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)}; + BSTR path; + IUri *uri; HRESULT hres; TRACE("(%p)->(%p)\n", This, p); @@ -467,19 +468,21 @@ static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p) if(!p) return E_POINTER; - url.dwUrlPathLength = 1; - url.dwExtraInfoLength = 1; - hres = get_url_components(This, &url); + if(!(uri = get_uri(This))) { + FIXME("No current URI\n"); + return E_NOTIMPL; + } + + hres = IUri_GetPath(uri, &path); if(FAILED(hres)) return hres; - if(url.dwUrlPathLength && url.lpszUrlPath[0] == '/') - *p = SysAllocStringLen(url.lpszUrlPath + 1, url.dwUrlPathLength - 1); - else - *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength); + if(hres == S_FALSE) { + SysFreeString(path); + path = NULL; + } - if(!*p) - return E_OUTOFMEMORY; + *p = path; return S_OK; } diff --git a/dlls/mshtml/tests/elements.js b/dlls/mshtml/tests/elements.js index be37d90fdf..60e4a7e16e 100644 --- a/dlls/mshtml/tests/elements.js +++ b/dlls/mshtml/tests/elements.js @@ -126,6 +126,22 @@ function test_iframe() { }); } +function test_iframe_location() { + document.body.innerHTML = '' + var iframe = document.body.firstChild; + + iframe.onload = function() { + ok(iframe.contentWindow.location.pathname === "/emptyfile", + "path = " + iframe.contentWindow.location.pathname); + iframe.onload = function () { + ok(iframe.contentWindow.location.pathname === "/empty/file", + "path = " + iframe.contentWindow.location.pathname); + next_test(); + } + iframe.src = "empty/file"; + } +} + function test_anchor() { var iframe = document.body.firstChild; var anchor = document.createElement("a"); @@ -420,6 +436,7 @@ var tests = [ test_createElementNS, test_head, test_iframe, + test_iframe_location, test_anchor, test_query_selector, test_compare_position, diff --git a/dlls/mshtml/tests/htmllocation.c b/dlls/mshtml/tests/htmllocation.c index 3d81eb6cd8..120ab7e25c 100644 --- a/dlls/mshtml/tests/htmllocation.c +++ b/dlls/mshtml/tests/htmllocation.c @@ -240,6 +240,9 @@ static void test_pathname(IHTMLLocation *loc, const struct location_test *test) hres = IHTMLLocation_get_pathname(loc, &str); ok(hres == S_OK, "%s: get_pathname failed: 0x%08x\n", test->name, hres); if(hres == S_OK) + /* FIXME: We seem to be testing location in a buggy state. Path names do not + * include leading slash, while other tests confirm that it should be there */ + todo_wine_if(*test->pathname == '/') ok(str_eq_wa(str, *test->pathname == '/' ? test->pathname + 1 : test->pathname), "%s: expected retrieved pathname to be L\"%s\", was: %s\n", test->name, test->pathname, wine_dbgstr_w(str)); diff --git a/dlls/mshtml/tests/script.c b/dlls/mshtml/tests/script.c index 7d6afd269e..e5466499bb 100644 --- a/dlls/mshtml/tests/script.c +++ b/dlls/mshtml/tests/script.c @@ -3087,6 +3087,8 @@ static HRESULT WINAPI ProtocolEx_StartEx(IInternetProtocolEx *iface, IUri *uri, HRSRC src; HRESULT hres; + static const WCHAR empty_prefixW[] = {'/','e','m','p','t','y'}; + hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &This->bind_info); ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres); @@ -3121,6 +3123,10 @@ static HRESULT WINAPI ProtocolEx_StartEx(IInternetProtocolEx *iface, IUri *uri, register_stream(This, query+1); SysFreeString(query); block = TRUE; + }else if(SysStringLen(path) >= ARRAY_SIZE(empty_prefixW) && !memcmp(path, empty_prefixW, sizeof(empty_prefixW))) { + static char empty_data[] = " "; + This->data = empty_data; + This->size = strlen(This->data); }else { src = FindResourceW(NULL, *path == '/' ? path+1 : path, (const WCHAR*)RT_HTML); ok(src != NULL, "Could not find resource for path %s\n", wine_dbgstr_w(path));