From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/script.c | 25 +++++++++++++++---------- dlls/mshtml/tests/dom.c | 1 - 2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/dlls/mshtml/script.c b/dlls/mshtml/script.c index 9d663ee1cf7..065c3568410 100644 --- a/dlls/mshtml/script.c +++ b/dlls/mshtml/script.c @@ -963,6 +963,7 @@ typedef struct {
static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret) { + binding_bom_t bom; UINT cp = CP_UTF8; WCHAR *text;
@@ -975,8 +976,19 @@ static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret) return S_OK; }
- switch(bsc->bsc.bom) { - case BOM_UTF16: + bom = bsc->bsc.bom; + if(bom == BOM_NONE) { + /* FIXME: Try to use charset from HTTP headers first */ + + /* IE guesses the encoding here using heuristics. Since valid script must start with an + * ASCII char (keyword, comment slash, string literal char, etc) that should be enough. */ + if(bsc->bsc.read > sizeof(WCHAR) && *(WCHAR*)bsc->buf < 128) + bom = BOM_UTF16; + else + cp = get_document_charset(bsc->script_elem->element.node.doc); + } + + if(bom == BOM_UTF16) { if(bsc->bsc.read % sizeof(WCHAR)) { FIXME("The buffer is not a valid utf16 string\n"); return E_FAIL; @@ -988,13 +1000,7 @@ static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret)
memcpy(text, bsc->buf, bsc->bsc.read); text[bsc->bsc.read/sizeof(WCHAR)] = 0; - break; - - default: - /* FIXME: Try to use charset from HTTP headers first */ - cp = get_document_charset(bsc->script_elem->element.node.doc); - /* fall through */ - case BOM_UTF8: { + }else { DWORD len;
len = MultiByteToWideChar(cp, 0, bsc->buf, bsc->bsc.read, NULL, 0); @@ -1005,7 +1011,6 @@ static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret) MultiByteToWideChar(cp, 0, bsc->buf, bsc->bsc.read, text, len); text[len] = 0; } - }
*ret = text; return S_OK; diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index b09c5ef971f..cd03db02df8 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -12173,7 +12173,6 @@ static void test_default_content_charset(void)
bstr = SysAllocString(L"wineTestProp"); hres = IHTMLDocument2_GetIDsOfNames(doc, &IID_NULL, &bstr, 1, 0, &dispid); - todo_wine_if((doc_charset == utf8 || doc_charset == utf16) && rsrc_charset == utf16) ok(hres == S_OK, "[%s:%s] GetIDsOfNames(wineTestProp) returned: %08lx\n", charsets[doc_charset], charsets[rsrc_charset], hres); SysFreeString(bstr);