Reviewed, tweaked and landed by Alexey.
- fix http://bugs.webkit.org/show_bug.cgi?id=17732
We didn't have a fallback to frame encoding in the case of loading a script via
changing its src attribute.
Test: fast/dom/HTMLScriptElement/script-decoding-error-after-setting-src.html
* html/HTMLScriptElement.cpp:
(WebCore::HTMLScriptElement::parseMappedAttribute): Use a helper function to get proper
charset for correct decoding of script content.
(WebCore::HTMLScriptElement::insertedIntoDocument):
(WebCore::HTMLScriptElement::scriptCharset): A helper function for getting proper charset
for the script (as much as can be determined prior to loading it).
* html/HTMLScriptElement.h:
* html/HTMLTokenizer.cpp:
(WebCore::HTMLTokenizer::parseTag): Use a helper function to get proper charset for correct
decoding of script content.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30928 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/html/HTMLScriptElement.cpp b/WebCore/html/HTMLScriptElement.cpp
index 0d5209c..ced0fdc 100644
--- a/WebCore/html/HTMLScriptElement.cpp
+++ b/WebCore/html/HTMLScriptElement.cpp
@@ -82,7 +82,7 @@
const AtomicString& url = attr->value();
if (!url.isEmpty()) {
- m_cachedScript = document()->docLoader()->requestScript(url, getAttribute(charsetAttr));
+ m_cachedScript = document()->docLoader()->requestScript(url, scriptCharset());
if (m_cachedScript)
m_cachedScript->ref(this);
else
@@ -120,12 +120,7 @@
const AtomicString& url = getAttribute(srcAttr);
if (!url.isEmpty()) {
- String scriptSrcCharset = getAttribute(charsetAttr).string().stripWhiteSpace();
- if (scriptSrcCharset.isEmpty()) {
- if (Frame* frame = document()->frame())
- scriptSrcCharset = frame->loader()->encoding();
- }
- m_cachedScript = document()->docLoader()->requestScript(url, scriptSrcCharset);
+ m_cachedScript = document()->docLoader()->requestScript(url, scriptCharset());
if (m_cachedScript)
m_cachedScript->ref(this);
else
@@ -331,4 +326,17 @@
setAttribute(typeAttr, value);
}
+String HTMLScriptElement::scriptCharset() const
+{
+ // First we try to get encoding from charset attribute.
+ String charset = getAttribute(charsetAttr).string().stripWhiteSpace();
+ // If charset has not been declared in script tag, fall back
+ // to frame encoding.
+ if (charset.isEmpty()) {
+ if (Frame* frame = document()->frame())
+ charset = frame->loader()->encoding();
+ }
+ return charset;
+}
+
}