From cb7155f1bd210288f9efb683024e00d876993ffd Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Mon, 25 Nov 2013 10:06:56 +0200 Subject: [PATCH] Bug 941562 - Make the encoding of documents that declare HZ unoverridable. r=emk. --HG-- rename : docshell/test/browser/browser_bug234628-6.js => docshell/test/browser/browser_bug941562.js rename : docshell/test/browser/file_bug234628-7-child.html => docshell/test/browser/file_bug941562-child.html rename : docshell/test/browser/file_bug234628-6.html => docshell/test/browser/file_bug941562.html --- docshell/test/browser/browser.ini | 3 ++ docshell/test/browser/browser_bug941562.js | 39 +++++++++++++++++++ .../test/browser/file_bug941562-child.html | 12 ++++++ docshell/test/browser/file_bug941562.html | 18 +++++++++ dom/encoding/EncodingUtils.cpp | 1 + 5 files changed, 73 insertions(+) create mode 100644 docshell/test/browser/browser_bug941562.js create mode 100644 docshell/test/browser/file_bug941562-child.html create mode 100644 docshell/test/browser/file_bug941562.html diff --git a/docshell/test/browser/browser.ini b/docshell/test/browser/browser.ini index 29b67e13005..3f55efbfb39 100644 --- a/docshell/test/browser/browser.ini +++ b/docshell/test/browser/browser.ini @@ -30,6 +30,8 @@ support-files = file_bug503832.html file_bug655270.html file_bug670318.html + file_bug941562-child.html + file_bug941562.html print_postdata.sjs test-form_sjis.html @@ -58,6 +60,7 @@ support-files = [browser_bug670318.js] [browser_bug673467.js] [browser_bug92473.js] +[browser_bug941562.js] [browser_loadDisallowInherit.js] [browser_loadURI.js] [browser_search_notification.js] diff --git a/docshell/test/browser/browser_bug941562.js b/docshell/test/browser/browser_bug941562.js new file mode 100644 index 00000000000..6f564e74bf8 --- /dev/null +++ b/docshell/test/browser/browser_bug941562.js @@ -0,0 +1,39 @@ +function test() { + waitForExplicitFinish(); + + var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/"; + gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug941562.html"); + gBrowser.selectedBrowser.addEventListener("load", afterOpen, true); +} + +function afterOpen(event) { + if (event.target != gBrowser.contentDocument) { + return; + } + + gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true); + gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true); + + is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 140, "Parent doc should be windows-1252 initially"); + + is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u4E2D'), 77, "Child doc should be HZ-GB-2312 initially"); + + BrowserSetForcedCharacterSet("windows-1251"); +} + +function afterChangeCharset(event) { + if (event.target != gBrowser.contentDocument) { + return; + } + + gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true); + + is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 140, "Parent doc should decode as windows-1251 subsequently"); + is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u4E2D'), 77, "Child doc should decode as HZ-GB-2312 subsequently"); + + is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently"); + is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "HZ-GB-2312", "Child doc should report HZ-GB-2312 subsequently"); + + gBrowser.removeCurrentTab(); + finish(); +} diff --git a/docshell/test/browser/file_bug941562-child.html b/docshell/test/browser/file_bug941562-child.html new file mode 100644 index 00000000000..eae29f85f2d --- /dev/null +++ b/docshell/test/browser/file_bug941562-child.html @@ -0,0 +1,12 @@ + + + + + +meta declaration in parent and meta HZ in child + + +

China if decoded as HZ: ~{VP~}

+ + + diff --git a/docshell/test/browser/file_bug941562.html b/docshell/test/browser/file_bug941562.html new file mode 100644 index 00000000000..0966f52f836 --- /dev/null +++ b/docshell/test/browser/file_bug941562.html @@ -0,0 +1,18 @@ + + + + + +meta declaration in parent and meta HZ in child + + +

meta declaration in parent and meta HZ in child

+ +

Euro sign if decoded as Windows-1252: €

+

a with diaeresis if decoded as Windows-1252: ä

+ + + + + + diff --git a/dom/encoding/EncodingUtils.cpp b/dom/encoding/EncodingUtils.cpp index 90c366d4c98..76c82ea2408 100644 --- a/dom/encoding/EncodingUtils.cpp +++ b/dom/encoding/EncodingUtils.cpp @@ -39,6 +39,7 @@ EncodingUtils::IsAsciiCompatible(const nsACString& aPreferredName) aPreferredName.LowerCaseEqualsLiteral("utf-16be") || aPreferredName.LowerCaseEqualsLiteral("utf-16le") || aPreferredName.LowerCaseEqualsLiteral("replacement") || + aPreferredName.LowerCaseEqualsLiteral("hz-gb-2312") || aPreferredName.LowerCaseEqualsLiteral("utf-7") || aPreferredName.LowerCaseEqualsLiteral("x-imap4-modified-utf7")); }