Fix character set used for dynamically loaded scripts.
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Dec 2007 08:43:02 +0000 (08:43 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Dec 2007 08:43:02 +0000 (08:43 +0000)
Reviewed by Weinig, Dan and Alexey.

Fix for:
    <rdar://problem/5333163> Safari can not display the mouse over pop menu on ChinaTimes News site correctly.
    <rdar://problem/5530048> [Safari]? :Leopard9A576: The typed CH characters displays as garbage in Sina website after reloading the webpage.
    <rdar://problem/5416588> All menus for chinese IBM site have wrong encoding

Use the same logic to determine the charset for a script loaded dynamically
as we do for a statically loaded script.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28612 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/encoding/no-charset-on-dynamic-script-load-expected.txt [new file with mode: 0644]
LayoutTests/fast/encoding/no-charset-on-dynamic-script-load.html [new file with mode: 0644]
LayoutTests/fast/encoding/resources/dynamic-load-target.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLScriptElement.cpp

index 356d14a..9eb142f 100644 (file)
@@ -1,3 +1,13 @@
+2007-12-10  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Weinig, Dan and Alexey.
+        
+        Layout test to confirm correct character encoding is used to
+        load dynamically loaded scripts.
+
+        * fast/encoding/no-charset-on-dynamic-script-load.html: Added.
+        * fast/encoding/resources/dynamic-load-target.js: Added.
+
 2007-12-10  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by Oliver Hunt.
diff --git a/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load-expected.txt b/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load-expected.txt
new file mode 100644 (file)
index 0000000..b817801
--- /dev/null
@@ -0,0 +1,2 @@
+This page tests that the character encoding is used for dynamically loaded scripts when no charset is specified directly or provided by the server.
+PASS: UTF-8 was correctly used for this script.
diff --git a/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load.html b/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load.html
new file mode 100644 (file)
index 0000000..363c261
--- /dev/null
@@ -0,0 +1,22 @@
+<html>
+    <head>
+        <title>Encoding test.</title>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
+           </head>
+    <body>
+        This page tests that the character encoding is used for dynamically loaded 
+        scripts when no charset is specified directly or provided by the server.
+        
+        <div id="target"></div>
+        <script>
+            if (window.layoutTestController) {
+                window.layoutTestController.waitUntilDone();
+                window.layoutTestController.dumpAsText();
+            }
+            tokyo = 'とうきょう';
+            oDIVResults=document.createElement('script'); 
+            oDIVResults.src="resources/dynamic-load-target.js";
+            document.getElementsByTagName("head").item(0).appendChild(oDIVResults);
+        </script>
+    </body>
+</html>
diff --git a/LayoutTests/fast/encoding/resources/dynamic-load-target.js b/LayoutTests/fast/encoding/resources/dynamic-load-target.js
new file mode 100644 (file)
index 0000000..6a0e175
--- /dev/null
@@ -0,0 +1,9 @@
+
+
+if ('とうきょう' == tokyo)
+    document.getElementById("target").innerHTML = "PASS: UTF-8 was correctly used for this script.";
+else
+    document.getElementById("target").innerHTML = "FAIL: Incorrect encoding used.  Expected '" + tokyo + "' but got '" + 'とうきょう' + "'.";
+
+if (window.layoutTestController) 
+    window.layoutTestController.notifyDone();
index fea6413..50e74bf 100644 (file)
@@ -1,3 +1,20 @@
+2007-12-10  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Weinig, Dan, and Alexey.
+
+        Fix character set used for dynamically loaded scripts.
+
+        Fix for:
+            <rdar://problem/5333163> Safari can not display the mouse over pop menu on ChinaTimes News site correctly.
+            <rdar://problem/5530048> [Safari]? :Leopard9A576: The typed CH characters displays as garbage in Sina website after reloading the webpage.
+            <rdar://problem/5416588> All menus for chinese IBM site have wrong encoding
+            
+        Use the same logic to determine the charset for a script loaded dynamically
+        as we do for a statically loaded script.
+
+        * html/HTMLScriptElement.cpp:
+        (WebCore::HTMLScriptElement::insertedIntoDocument):
+
 2007-12-10  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by Oliver Hunt.
index d4ac9ba..778a36b 100644 (file)
@@ -29,6 +29,7 @@
 #include "Document.h"
 #include "EventNames.h"
 #include "Frame.h"
+#include "FrameLoader.h"
 #include "HTMLNames.h"
 #include "kjs_proxy.h"
 #include "Text.h"
@@ -118,7 +119,12 @@ void HTMLScriptElement::insertedIntoDocument()
     
     const AtomicString& url = getAttribute(srcAttr);
     if (!url.isEmpty()) {
-        m_cachedScript = document()->docLoader()->requestScript(url, getAttribute(charsetAttr));
+        String scriptSrcCharset = getAttribute(charsetAttr).domString().stripWhiteSpace();
+        if (scriptSrcCharset.isEmpty()) {
+            if (Frame* frame = document()->frame())
+                scriptSrcCharset = frame->loader()->encoding();
+        }
+        m_cachedScript = document()->docLoader()->requestScript(url, scriptSrcCharset);
         if (m_cachedScript)
             m_cachedScript->ref(this);
         else