Skip to content
Permalink
Browse files
html/semantics/scripting-1/the-script-element/script-type-and-languag…
…e-empty.html WPT test is failing

https://bugs.webkit.org/show_bug.cgi?id=235202

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaseline test that is now passing.

* web-platform-tests/html/semantics/scripting-1/the-script-element/script-type-and-language-empty-expected.txt:

Source/WebCore:

Per https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script (step 8), we should assume
the type is "text/javascript" if the type attribute is present and its value is the empty string.
Our logic in ScriptElement::determineScriptType() was slightly wrong and didn't get this case right
because it was doing an `isEmpty()` check which could mean both that the attribute is missing or present
with a value that is the empty string.

No new tests, rebaselined existing test.

* dom/ScriptElement.cpp:
(WebCore::ScriptElement::determineScriptType const):



Canonical link: https://commits.webkit.org/246030@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288004 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Jan 14, 2022
1 parent c071c13 commit ab2e96b25cea84c6ebb85f39973b52341b7f82fe
@@ -41,9 +41,17 @@ Type: "", Language: "javascript1.4"
Type: "", Language: "javascript1.5"
Type: "", Language: "javascript1.6"
Type: "", Language: "javascript1.7"
Type: "", Language: "javascript1.8"
Type: "", Language: "javascript1.9"
Type: "", Language: "ecmascript"
Type: "", Language: "livescript"
Type: "", Language: "jscript"
Type: "", Language: "ebayScript"
Type: "", Language: " "
Type: "", Language: " javascript"
Type: "", Language: "javascript "
Type: "", Language: " javascript "
Type: "", Language: "abcdefg"
When a type is specified, the language attribute should be ignored.
Type: "text/javascript", Language: ""
Type: "text/javascript", Language: "javascript"
@@ -168,5 +168,5 @@ empty string language, "text/javascript" type executed
These scripts should not execute

"javascript" language, "bogus" type
empty string type, "bogus" language
empty string type, "bogus" language executed
empty string language, "bogus" type
@@ -1,3 +1,14 @@
2022-01-13 Chris Dumez <cdumez@apple.com>

html/semantics/scripting-1/the-script-element/script-type-and-language-empty.html WPT test is failing
https://bugs.webkit.org/show_bug.cgi?id=235202

Reviewed by Darin Adler.

Rebaseline test that is now passing.

* web-platform-tests/html/semantics/scripting-1/the-script-element/script-type-and-language-empty-expected.txt:

2022-01-13 Chris Dumez <cdumez@apple.com>

Implement HTMLScriptElement.supports(type) method
@@ -1,6 +1,6 @@

PASS A script with empty type and no language should run
FAIL A script with empty type and a random language should run assert_true: expected true got false
PASS A script with empty type and a random language should run
PASS A script with empty type and empty language should run
PASS A script with no type and empty language should run

@@ -1,3 +1,21 @@
2022-01-13 Chris Dumez <cdumez@apple.com>

html/semantics/scripting-1/the-script-element/script-type-and-language-empty.html WPT test is failing
https://bugs.webkit.org/show_bug.cgi?id=235202

Reviewed by Darin Adler.

Per https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script (step 8), we should assume
the type is "text/javascript" if the type attribute is present and its value is the empty string.
Our logic in ScriptElement::determineScriptType() was slightly wrong and didn't get this case right
because it was doing an `isEmpty()` check which could mean both that the attribute is missing or present
with a value that is the empty string.

No new tests, rebaselined existing test.

* dom/ScriptElement.cpp:
(WebCore::ScriptElement::determineScriptType const):

2022-01-13 Cameron McCormack <heycam@apple.com>

Only apply automatic minimum block-size aspect-ratio rules to non-replaced elements
@@ -135,14 +135,15 @@ void ScriptElement::dispatchErrorEvent()
m_element.dispatchEvent(Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
}

// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script
std::optional<ScriptElement::ScriptType> ScriptElement::determineScriptType(LegacyTypeSupport supportLegacyTypes) const
{
// FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is used here to maintain backwards compatibility with existing layout tests. The specific violations are:
// - Allowing type=javascript. type= should only support MIME types, such as text/javascript.
// - Allowing a different set of languages for language= and type=. language= supports Javascript 1.1 and 1.4-1.6, but type= does not.
String type = typeAttributeValue();
String language = languageAttributeValue();
if (type.isEmpty()) {
if (type.isNull()) {
if (language.isEmpty())
return ScriptType::Classic; // Assume text/javascript.
if (MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + language))
@@ -151,6 +152,9 @@ std::optional<ScriptElement::ScriptType> ScriptElement::determineScriptType(Lega
return ScriptType::Classic;
return std::nullopt;
}
if (type.isEmpty())
return ScriptType::Classic; // Assume text/javascript.

if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSpace()))
return ScriptType::Classic;
if (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && isLegacySupportedJavaScriptLanguage(type))

0 comments on commit ab2e96b

Please sign in to comment.