diff --git a/dlls/mshtml/protocol.c b/dlls/mshtml/protocol.c
index 2499db4fbd5..9988c90c1b9 100644
--- a/dlls/mshtml/protocol.c
+++ b/dlls/mshtml/protocol.c
@@ -649,7 +649,7 @@ static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
/* Ignore query and hash parts. */
if((ptr = strchrW(url_file, '?')))
*ptr = 0;
- if((ptr = strchrW(url_file, '#')))
+ if(*url_file && (ptr = strchrW(url_file+1, '#')))
*ptr = 0;
hdll = LoadLibraryExW(url_dll, NULL, LOAD_LIBRARY_AS_DATAFILE);
diff --git a/dlls/mshtml/tests/protocol.c b/dlls/mshtml/tests/protocol.c
index 00971be2cc6..f9803dfb48d 100644
--- a/dlls/mshtml/tests/protocol.c
+++ b/dlls/mshtml/tests/protocol.c
@@ -606,6 +606,9 @@ static void test_res_protocol(void)
if(GetProcAddress(LoadLibraryA("urlmon.dll"), "CreateUri")) {
test_res_url("/test/dir/dir2/res.html?query_part");
test_res_url("/test/dir/dir2/res.html#hash_part");
+ test_res_url("/#123");
+ test_res_url("/#23/#123");
+ test_res_url("/#123#456");
}else {
win_skip("IUri not supported\n");
}
diff --git a/dlls/mshtml/tests/rsrc.rc b/dlls/mshtml/tests/rsrc.rc
index d498b8295f3..33ffef59c46 100644
--- a/dlls/mshtml/tests/rsrc.rc
+++ b/dlls/mshtml/tests/rsrc.rc
@@ -40,6 +40,9 @@ blank.html HTML "blank.html"
/* @makedep: blank.html */
blank2.html HTML "blank.html"
+/* @makedep: blank.html */
+123 HTML "blank.html"
+
/* @makedep: test_tlb.tlb */
1 TYPELIB test_tlb.tlb