Commit cd71c5f4 authored by Amos Lim's avatar Amos Lim Committed by Commit Bot

Fix invalid charset detection in a meta element

Fix invalid charset detection when a meta contains both a "charset" and
a "content" attribute. The encoding specified in the "charset" attribute should
have precedence over the one in the "content" attribute.

https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead

Bug: 855047
Change-Id: I79306fc0bff8f094800a989d8d548bd94b96b5eb
Reviewed-on: https://chromium-review.googlesource.com/1172462Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Amos Lim <eui-sang.lim@samsung.com>
Cr-Commit-Position: refs/heads/master@{#582845}
parent 180a0fc9
<!DOCTYPE html>
<html>
<head>
<title>Encoding specified in the "charset" attribute should have precedence over "content" attribute.</title>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r" charset="iso-8859-15">
<link rel="help" href="https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
test(function () {
assert_equals(document.characterSet, "ISO-8859-15");
}, "Encoding specified in the 'charset' attribute should have precedence over 'content' attribute.");
</script>
</body>
</html>
...@@ -372,6 +372,7 @@ enum class MetaAttribute { ...@@ -372,6 +372,7 @@ enum class MetaAttribute {
WTF::TextEncoding EncodingFromMetaAttributes( WTF::TextEncoding EncodingFromMetaAttributes(
const HTMLAttributeList& attributes) { const HTMLAttributeList& attributes) {
bool got_pragma = false; bool got_pragma = false;
bool has_charset = false;
MetaAttribute mode = MetaAttribute::kNone; MetaAttribute mode = MetaAttribute::kNone;
String charset; String charset;
...@@ -382,15 +383,14 @@ WTF::TextEncoding EncodingFromMetaAttributes( ...@@ -382,15 +383,14 @@ WTF::TextEncoding EncodingFromMetaAttributes(
if (ThreadSafeMatch(attribute_name, http_equivAttr)) { if (ThreadSafeMatch(attribute_name, http_equivAttr)) {
if (DeprecatedEqualIgnoringCase(attribute_value, "content-type")) if (DeprecatedEqualIgnoringCase(attribute_value, "content-type"))
got_pragma = true; got_pragma = true;
} else if (charset.IsEmpty()) { } else if (ThreadSafeMatch(attribute_name, charsetAttr)) {
if (ThreadSafeMatch(attribute_name, charsetAttr)) { has_charset = true;
charset = attribute_value; charset = attribute_value;
mode = MetaAttribute::kCharset; mode = MetaAttribute::kCharset;
} else if (ThreadSafeMatch(attribute_name, contentAttr)) { } else if (!has_charset && ThreadSafeMatch(attribute_name, contentAttr)) {
charset = ExtractCharset(attribute_value); charset = ExtractCharset(attribute_value);
if (charset.length()) if (charset.length())
mode = MetaAttribute::kPragma; mode = MetaAttribute::kPragma;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment