LibWeb/SVG: Respect script element type attribute

Previously, scripts would run regardless of the value of this attribute.
This commit is contained in:
Tim Ledbetter 2025-02-26 12:53:43 +00:00 committed by Jelle Raaijmakers
parent f4c4d3c780
commit d114f13029
Notes: github-actions[bot] 2025-02-26 15:09:48 +00:00
5 changed files with 654 additions and 1 deletions

View file

@ -82,6 +82,7 @@ namespace Web::SVG::AttributeNames {
__ENUMERATE_SVG_ATTRIBUTE(targetX, "targetX") \
__ENUMERATE_SVG_ATTRIBUTE(targetY, "targetY") \
__ENUMERATE_SVG_ATTRIBUTE(textLength, "textLength") \
__ENUMERATE_SVG_ATTRIBUTE(type, "type") \
__ENUMERATE_SVG_ATTRIBUTE(version, "version") \
__ENUMERATE_SVG_ATTRIBUTE(viewBox, "viewBox") \
__ENUMERATE_SVG_ATTRIBUTE(viewTarget, "viewTarget") \

View file

@ -38,7 +38,7 @@ void SVGScriptElement::visit_edges(Cell::Visitor& visitor)
void SVGScriptElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
{
Base::attribute_changed(name, old_value, value, namespace_);
if (name == SVG::AttributeNames::href) {
if (name == SVG::AttributeNames::href || name == SVG::AttributeNames::type) {
process_the_script_element();
}
}
@ -69,6 +69,19 @@ void SVGScriptElement::process_the_script_element()
if (m_already_processed || !in_a_document_tree())
return;
// https://svgwg.org/svg2-draft/interact.html#ScriptElement
// Before attempting to execute the script element the resolved media type value for type must be inspected.
// If the SVG user agent does not support the scripting language then the script element must not be executed.
// FIXME: Support type="module" scripts
auto maybe_script_type = attribute(SVG::AttributeNames::type);
if (maybe_script_type.has_value() && !maybe_script_type->is_empty()) {
auto script_type = MUST(maybe_script_type->to_ascii_lowercase().trim_ascii_whitespace());
if (!MimeSniff::is_javascript_mime_type_essence_match(script_type)) {
dbgln("SVGScriptElement: Unsupported script type: {}", *maybe_script_type);
return;
}
}
IGNORE_USE_IN_ESCAPING_LAMBDA String script_content;
auto script_url = m_document->url();

View file

@ -0,0 +1,461 @@
Harness status: OK
Found 456 tests
456 Pass
Pass Script should run with type=""
Pass Script shouldn't run with type=" "
Pass Script should run with type="application/ecmascript"
Pass Script should run with type="application/javascript"
Pass Script should run with type="application/x-ecmascript"
Pass Script should run with type="application/x-javascript"
Pass Script should run with type="APPLICATION/ECMASCRIPT"
Pass Script should run with type="APPLICATION/JAVASCRIPT"
Pass Script should run with type="APPLICATION/X-ECMASCRIPT"
Pass Script should run with type="APPLICATION/X-JAVASCRIPT"
Pass Script should run with type="application/ecmascript "
Pass Script should run with type="application/javascript "
Pass Script should run with type="application/x-ecmascript "
Pass Script should run with type="application/x-javascript "
Pass Script should run with type=" application/ecmascript"
Pass Script should run with type=" application/javascript"
Pass Script should run with type=" application/x-ecmascript"
Pass Script should run with type=" application/x-javascript"
Pass Script should run with type="application/ecmascript\t"
Pass Script should run with type="application/javascript\t"
Pass Script should run with type="application/x-ecmascript\t"
Pass Script should run with type="application/x-javascript\t"
Pass Script should run with type="\tapplication/ecmascript"
Pass Script should run with type="\tapplication/javascript"
Pass Script should run with type="\tapplication/x-ecmascript"
Pass Script should run with type="\tapplication/x-javascript"
Pass Script should run with type="application/ecmascript\n"
Pass Script should run with type="application/javascript\n"
Pass Script should run with type="application/x-ecmascript\n"
Pass Script should run with type="application/x-javascript\n"
Pass Script should run with type="\napplication/ecmascript"
Pass Script should run with type="\napplication/javascript"
Pass Script should run with type="\napplication/x-ecmascript"
Pass Script should run with type="\napplication/x-javascript"
Pass Script should run with type="application/ecmascript\r"
Pass Script should run with type="application/javascript\r"
Pass Script should run with type="application/x-ecmascript\r"
Pass Script should run with type="application/x-javascript\r"
Pass Script should run with type="\rapplication/ecmascript"
Pass Script should run with type="\rapplication/javascript"
Pass Script should run with type="\rapplication/x-ecmascript"
Pass Script should run with type="\rapplication/x-javascript"
Pass Script should run with type="application/ecmascript\f"
Pass Script should run with type="application/javascript\f"
Pass Script should run with type="application/x-ecmascript\f"
Pass Script should run with type="application/x-javascript\f"
Pass Script should run with type="\fapplication/ecmascript"
Pass Script should run with type="\fapplication/javascript"
Pass Script should run with type="\fapplication/x-ecmascript"
Pass Script should run with type="\fapplication/x-javascript"
Pass Script shouldn't run with type="application/ecmascript\0"
Pass Script shouldn't run with type="application/javascript\0"
Pass Script shouldn't run with type="application/x-ecmascript\0"
Pass Script shouldn't run with type="application/x-javascript\0"
Pass Script shouldn't run with type="application/ecmascript\0foo"
Pass Script shouldn't run with type="application/javascript\0foo"
Pass Script shouldn't run with type="application/x-ecmascript\0foo"
Pass Script shouldn't run with type="application/x-javascript\0foo"
Pass Script should run with type="text/ecmascript"
Pass Script should run with type="text/javascript"
Pass Script should run with type="text/javascript1.0"
Pass Script should run with type="text/javascript1.1"
Pass Script should run with type="text/javascript1.2"
Pass Script should run with type="text/javascript1.3"
Pass Script should run with type="text/javascript1.4"
Pass Script should run with type="text/javascript1.5"
Pass Script should run with type="text/jscript"
Pass Script should run with type="text/livescript"
Pass Script should run with type="text/x-ecmascript"
Pass Script should run with type="text/x-javascript"
Pass Script should run with type="TEXT/ECMASCRIPT"
Pass Script should run with type="TEXT/JAVASCRIPT"
Pass Script should run with type="TEXT/JAVASCRIPT1.0"
Pass Script should run with type="TEXT/JAVASCRIPT1.1"
Pass Script should run with type="TEXT/JAVASCRIPT1.2"
Pass Script should run with type="TEXT/JAVASCRIPT1.3"
Pass Script should run with type="TEXT/JAVASCRIPT1.4"
Pass Script should run with type="TEXT/JAVASCRIPT1.5"
Pass Script should run with type="TEXT/JSCRIPT"
Pass Script should run with type="TEXT/LIVESCRIPT"
Pass Script should run with type="TEXT/X-ECMASCRIPT"
Pass Script should run with type="TEXT/X-JAVASCRIPT"
Pass Script shouldn't run with type="text/javascript1.6"
Pass Script shouldn't run with type="text/javascript1.7"
Pass Script shouldn't run with type="text/javascript1.8"
Pass Script shouldn't run with type="text/javascript1.9"
Pass Script should run with type="text/ecmascript "
Pass Script should run with type="text/javascript "
Pass Script should run with type="text/javascript1.0 "
Pass Script should run with type="text/javascript1.1 "
Pass Script should run with type="text/javascript1.2 "
Pass Script should run with type="text/javascript1.3 "
Pass Script should run with type="text/javascript1.4 "
Pass Script should run with type="text/javascript1.5 "
Pass Script should run with type="text/jscript "
Pass Script should run with type="text/livescript "
Pass Script should run with type="text/x-ecmascript "
Pass Script should run with type="text/x-javascript "
Pass Script should run with type=" text/ecmascript"
Pass Script should run with type=" text/javascript"
Pass Script should run with type=" text/javascript1.0"
Pass Script should run with type=" text/javascript1.1"
Pass Script should run with type=" text/javascript1.2"
Pass Script should run with type=" text/javascript1.3"
Pass Script should run with type=" text/javascript1.4"
Pass Script should run with type=" text/javascript1.5"
Pass Script should run with type=" text/jscript"
Pass Script should run with type=" text/livescript"
Pass Script should run with type=" text/x-ecmascript"
Pass Script should run with type=" text/x-javascript"
Pass Script should run with type="text/ecmascript\t"
Pass Script should run with type="text/javascript\t"
Pass Script should run with type="text/javascript1.0\t"
Pass Script should run with type="text/javascript1.1\t"
Pass Script should run with type="text/javascript1.2\t"
Pass Script should run with type="text/javascript1.3\t"
Pass Script should run with type="text/javascript1.4\t"
Pass Script should run with type="text/javascript1.5\t"
Pass Script should run with type="text/jscript\t"
Pass Script should run with type="text/livescript\t"
Pass Script should run with type="text/x-ecmascript\t"
Pass Script should run with type="text/x-javascript\t"
Pass Script should run with type="\ttext/ecmascript"
Pass Script should run with type="\ttext/javascript"
Pass Script should run with type="\ttext/javascript1.0"
Pass Script should run with type="\ttext/javascript1.1"
Pass Script should run with type="\ttext/javascript1.2"
Pass Script should run with type="\ttext/javascript1.3"
Pass Script should run with type="\ttext/javascript1.4"
Pass Script should run with type="\ttext/javascript1.5"
Pass Script should run with type="\ttext/jscript"
Pass Script should run with type="\ttext/livescript"
Pass Script should run with type="\ttext/x-ecmascript"
Pass Script should run with type="\ttext/x-javascript"
Pass Script should run with type="text/ecmascript\n"
Pass Script should run with type="text/javascript\n"
Pass Script should run with type="text/javascript1.0\n"
Pass Script should run with type="text/javascript1.1\n"
Pass Script should run with type="text/javascript1.2\n"
Pass Script should run with type="text/javascript1.3\n"
Pass Script should run with type="text/javascript1.4\n"
Pass Script should run with type="text/javascript1.5\n"
Pass Script should run with type="text/jscript\n"
Pass Script should run with type="text/livescript\n"
Pass Script should run with type="text/x-ecmascript\n"
Pass Script should run with type="text/x-javascript\n"
Pass Script should run with type="\ntext/ecmascript"
Pass Script should run with type="\ntext/javascript"
Pass Script should run with type="\ntext/javascript1.0"
Pass Script should run with type="\ntext/javascript1.1"
Pass Script should run with type="\ntext/javascript1.2"
Pass Script should run with type="\ntext/javascript1.3"
Pass Script should run with type="\ntext/javascript1.4"
Pass Script should run with type="\ntext/javascript1.5"
Pass Script should run with type="\ntext/jscript"
Pass Script should run with type="\ntext/livescript"
Pass Script should run with type="\ntext/x-ecmascript"
Pass Script should run with type="\ntext/x-javascript"
Pass Script should run with type="text/ecmascript\r"
Pass Script should run with type="text/javascript\r"
Pass Script should run with type="text/javascript1.0\r"
Pass Script should run with type="text/javascript1.1\r"
Pass Script should run with type="text/javascript1.2\r"
Pass Script should run with type="text/javascript1.3\r"
Pass Script should run with type="text/javascript1.4\r"
Pass Script should run with type="text/javascript1.5\r"
Pass Script should run with type="text/jscript\r"
Pass Script should run with type="text/livescript\r"
Pass Script should run with type="text/x-ecmascript\r"
Pass Script should run with type="text/x-javascript\r"
Pass Script should run with type="\rtext/ecmascript"
Pass Script should run with type="\rtext/javascript"
Pass Script should run with type="\rtext/javascript1.0"
Pass Script should run with type="\rtext/javascript1.1"
Pass Script should run with type="\rtext/javascript1.2"
Pass Script should run with type="\rtext/javascript1.3"
Pass Script should run with type="\rtext/javascript1.4"
Pass Script should run with type="\rtext/javascript1.5"
Pass Script should run with type="\rtext/jscript"
Pass Script should run with type="\rtext/livescript"
Pass Script should run with type="\rtext/x-ecmascript"
Pass Script should run with type="\rtext/x-javascript"
Pass Script should run with type="text/ecmascript\f"
Pass Script should run with type="text/javascript\f"
Pass Script should run with type="text/javascript1.0\f"
Pass Script should run with type="text/javascript1.1\f"
Pass Script should run with type="text/javascript1.2\f"
Pass Script should run with type="text/javascript1.3\f"
Pass Script should run with type="text/javascript1.4\f"
Pass Script should run with type="text/javascript1.5\f"
Pass Script should run with type="text/jscript\f"
Pass Script should run with type="text/livescript\f"
Pass Script should run with type="text/x-ecmascript\f"
Pass Script should run with type="text/x-javascript\f"
Pass Script should run with type="\ftext/ecmascript"
Pass Script should run with type="\ftext/javascript"
Pass Script should run with type="\ftext/javascript1.0"
Pass Script should run with type="\ftext/javascript1.1"
Pass Script should run with type="\ftext/javascript1.2"
Pass Script should run with type="\ftext/javascript1.3"
Pass Script should run with type="\ftext/javascript1.4"
Pass Script should run with type="\ftext/javascript1.5"
Pass Script should run with type="\ftext/jscript"
Pass Script should run with type="\ftext/livescript"
Pass Script should run with type="\ftext/x-ecmascript"
Pass Script should run with type="\ftext/x-javascript"
Pass Script shouldn't run with type="text/ecmascript\0"
Pass Script shouldn't run with type="text/javascript\0"
Pass Script shouldn't run with type="text/javascript1.0\0"
Pass Script shouldn't run with type="text/javascript1.1\0"
Pass Script shouldn't run with type="text/javascript1.2\0"
Pass Script shouldn't run with type="text/javascript1.3\0"
Pass Script shouldn't run with type="text/javascript1.4\0"
Pass Script shouldn't run with type="text/javascript1.5\0"
Pass Script shouldn't run with type="text/jscript\0"
Pass Script shouldn't run with type="text/livescript\0"
Pass Script shouldn't run with type="text/x-ecmascript\0"
Pass Script shouldn't run with type="text/x-javascript\0"
Pass Script shouldn't run with type="text/ecmascript\0foo"
Pass Script shouldn't run with type="text/javascript\0foo"
Pass Script shouldn't run with type="text/javascript1.0\0foo"
Pass Script shouldn't run with type="text/javascript1.1\0foo"
Pass Script shouldn't run with type="text/javascript1.2\0foo"
Pass Script shouldn't run with type="text/javascript1.3\0foo"
Pass Script shouldn't run with type="text/javascript1.4\0foo"
Pass Script shouldn't run with type="text/javascript1.5\0foo"
Pass Script shouldn't run with type="text/jscript\0foo"
Pass Script shouldn't run with type="text/livescript\0foo"
Pass Script shouldn't run with type="text/x-ecmascript\0foo"
Pass Script shouldn't run with type="text/x-javascript\0foo"
Pass Script shouldn't run with type="ecmascript"
Pass Script shouldn't run with type="javascript"
Pass Script shouldn't run with type="javascript1.0"
Pass Script shouldn't run with type="javascript1.1"
Pass Script shouldn't run with type="javascript1.2"
Pass Script shouldn't run with type="javascript1.3"
Pass Script shouldn't run with type="javascript1.4"
Pass Script shouldn't run with type="javascript1.5"
Pass Script shouldn't run with type="jscript"
Pass Script shouldn't run with type="livescript"
Pass Script shouldn't run with type="x-ecmascript"
Pass Script shouldn't run with type="x-javascript"
Pass Script shouldn't run with type="javascript1.6"
Pass Script shouldn't run with type="javascript1.7"
Pass Script shouldn't run with type="javascript1.8"
Pass Script shouldn't run with type="javascript1.9"
Pass Script should run with language=""
Pass Script should run with language=" "
Pass Script should run with language="ecmascript"
Pass Script should run with language="javascript"
Pass Script should run with language="javascript1.0"
Pass Script should run with language="javascript1.1"
Pass Script should run with language="javascript1.2"
Pass Script should run with language="javascript1.3"
Pass Script should run with language="javascript1.4"
Pass Script should run with language="javascript1.5"
Pass Script should run with language="jscript"
Pass Script should run with language="livescript"
Pass Script should run with language="x-ecmascript"
Pass Script should run with language="x-javascript"
Pass Script should run with language="ECMASCRIPT"
Pass Script should run with language="JAVASCRIPT"
Pass Script should run with language="JAVASCRIPT1.0"
Pass Script should run with language="JAVASCRIPT1.1"
Pass Script should run with language="JAVASCRIPT1.2"
Pass Script should run with language="JAVASCRIPT1.3"
Pass Script should run with language="JAVASCRIPT1.4"
Pass Script should run with language="JAVASCRIPT1.5"
Pass Script should run with language="JSCRIPT"
Pass Script should run with language="LIVESCRIPT"
Pass Script should run with language="X-ECMASCRIPT"
Pass Script should run with language="X-JAVASCRIPT"
Pass Script should run with language="javascript1.6"
Pass Script should run with language="javascript1.7"
Pass Script should run with language="javascript1.8"
Pass Script should run with language="javascript1.9"
Pass Script should run with language="ecmascript "
Pass Script should run with language="javascript "
Pass Script should run with language="javascript1.0 "
Pass Script should run with language="javascript1.1 "
Pass Script should run with language="javascript1.2 "
Pass Script should run with language="javascript1.3 "
Pass Script should run with language="javascript1.4 "
Pass Script should run with language="javascript1.5 "
Pass Script should run with language="jscript "
Pass Script should run with language="livescript "
Pass Script should run with language="x-ecmascript "
Pass Script should run with language="x-javascript "
Pass Script should run with language=" ecmascript"
Pass Script should run with language=" javascript"
Pass Script should run with language=" javascript1.0"
Pass Script should run with language=" javascript1.1"
Pass Script should run with language=" javascript1.2"
Pass Script should run with language=" javascript1.3"
Pass Script should run with language=" javascript1.4"
Pass Script should run with language=" javascript1.5"
Pass Script should run with language=" jscript"
Pass Script should run with language=" livescript"
Pass Script should run with language=" x-ecmascript"
Pass Script should run with language=" x-javascript"
Pass Script should run with language="ecmascript\t"
Pass Script should run with language="javascript\t"
Pass Script should run with language="javascript1.0\t"
Pass Script should run with language="javascript1.1\t"
Pass Script should run with language="javascript1.2\t"
Pass Script should run with language="javascript1.3\t"
Pass Script should run with language="javascript1.4\t"
Pass Script should run with language="javascript1.5\t"
Pass Script should run with language="jscript\t"
Pass Script should run with language="livescript\t"
Pass Script should run with language="x-ecmascript\t"
Pass Script should run with language="x-javascript\t"
Pass Script should run with language="\tecmascript"
Pass Script should run with language="\tjavascript"
Pass Script should run with language="\tjavascript1.0"
Pass Script should run with language="\tjavascript1.1"
Pass Script should run with language="\tjavascript1.2"
Pass Script should run with language="\tjavascript1.3"
Pass Script should run with language="\tjavascript1.4"
Pass Script should run with language="\tjavascript1.5"
Pass Script should run with language="\tjscript"
Pass Script should run with language="\tlivescript"
Pass Script should run with language="\tx-ecmascript"
Pass Script should run with language="\tx-javascript"
Pass Script should run with language="ecmascript\n"
Pass Script should run with language="javascript\n"
Pass Script should run with language="javascript1.0\n"
Pass Script should run with language="javascript1.1\n"
Pass Script should run with language="javascript1.2\n"
Pass Script should run with language="javascript1.3\n"
Pass Script should run with language="javascript1.4\n"
Pass Script should run with language="javascript1.5\n"
Pass Script should run with language="jscript\n"
Pass Script should run with language="livescript\n"
Pass Script should run with language="x-ecmascript\n"
Pass Script should run with language="x-javascript\n"
Pass Script should run with language="\necmascript"
Pass Script should run with language="\njavascript"
Pass Script should run with language="\njavascript1.0"
Pass Script should run with language="\njavascript1.1"
Pass Script should run with language="\njavascript1.2"
Pass Script should run with language="\njavascript1.3"
Pass Script should run with language="\njavascript1.4"
Pass Script should run with language="\njavascript1.5"
Pass Script should run with language="\njscript"
Pass Script should run with language="\nlivescript"
Pass Script should run with language="\nx-ecmascript"
Pass Script should run with language="\nx-javascript"
Pass Script should run with language="ecmascript\r"
Pass Script should run with language="javascript\r"
Pass Script should run with language="javascript1.0\r"
Pass Script should run with language="javascript1.1\r"
Pass Script should run with language="javascript1.2\r"
Pass Script should run with language="javascript1.3\r"
Pass Script should run with language="javascript1.4\r"
Pass Script should run with language="javascript1.5\r"
Pass Script should run with language="jscript\r"
Pass Script should run with language="livescript\r"
Pass Script should run with language="x-ecmascript\r"
Pass Script should run with language="x-javascript\r"
Pass Script should run with language="\recmascript"
Pass Script should run with language="\rjavascript"
Pass Script should run with language="\rjavascript1.0"
Pass Script should run with language="\rjavascript1.1"
Pass Script should run with language="\rjavascript1.2"
Pass Script should run with language="\rjavascript1.3"
Pass Script should run with language="\rjavascript1.4"
Pass Script should run with language="\rjavascript1.5"
Pass Script should run with language="\rjscript"
Pass Script should run with language="\rlivescript"
Pass Script should run with language="\rx-ecmascript"
Pass Script should run with language="\rx-javascript"
Pass Script should run with language="ecmascript\f"
Pass Script should run with language="javascript\f"
Pass Script should run with language="javascript1.0\f"
Pass Script should run with language="javascript1.1\f"
Pass Script should run with language="javascript1.2\f"
Pass Script should run with language="javascript1.3\f"
Pass Script should run with language="javascript1.4\f"
Pass Script should run with language="javascript1.5\f"
Pass Script should run with language="jscript\f"
Pass Script should run with language="livescript\f"
Pass Script should run with language="x-ecmascript\f"
Pass Script should run with language="x-javascript\f"
Pass Script should run with language="\fecmascript"
Pass Script should run with language="\fjavascript"
Pass Script should run with language="\fjavascript1.0"
Pass Script should run with language="\fjavascript1.1"
Pass Script should run with language="\fjavascript1.2"
Pass Script should run with language="\fjavascript1.3"
Pass Script should run with language="\fjavascript1.4"
Pass Script should run with language="\fjavascript1.5"
Pass Script should run with language="\fjscript"
Pass Script should run with language="\flivescript"
Pass Script should run with language="\fx-ecmascript"
Pass Script should run with language="\fx-javascript"
Pass Script should run with language="ecmascriptxyz"
Pass Script should run with language="javascriptxyz"
Pass Script should run with language="javascript1.0xyz"
Pass Script should run with language="javascript1.1xyz"
Pass Script should run with language="javascript1.2xyz"
Pass Script should run with language="javascript1.3xyz"
Pass Script should run with language="javascript1.4xyz"
Pass Script should run with language="javascript1.5xyz"
Pass Script should run with language="jscriptxyz"
Pass Script should run with language="livescriptxyz"
Pass Script should run with language="x-ecmascriptxyz"
Pass Script should run with language="x-javascriptxyz"
Pass Script should run with language="xyzecmascript"
Pass Script should run with language="xyzjavascript"
Pass Script should run with language="xyzjavascript1.0"
Pass Script should run with language="xyzjavascript1.1"
Pass Script should run with language="xyzjavascript1.2"
Pass Script should run with language="xyzjavascript1.3"
Pass Script should run with language="xyzjavascript1.4"
Pass Script should run with language="xyzjavascript1.5"
Pass Script should run with language="xyzjscript"
Pass Script should run with language="xyzlivescript"
Pass Script should run with language="xyzx-ecmascript"
Pass Script should run with language="xyzx-javascript"
Pass Script should run with language="ecmascript\0"
Pass Script should run with language="javascript\0"
Pass Script should run with language="javascript1.0\0"
Pass Script should run with language="javascript1.1\0"
Pass Script should run with language="javascript1.2\0"
Pass Script should run with language="javascript1.3\0"
Pass Script should run with language="javascript1.4\0"
Pass Script should run with language="javascript1.5\0"
Pass Script should run with language="jscript\0"
Pass Script should run with language="livescript\0"
Pass Script should run with language="x-ecmascript\0"
Pass Script should run with language="x-javascript\0"
Pass Script should run with language="ecmascript\0foo"
Pass Script should run with language="javascript\0foo"
Pass Script should run with language="javascript1.0\0foo"
Pass Script should run with language="javascript1.1\0foo"
Pass Script should run with language="javascript1.2\0foo"
Pass Script should run with language="javascript1.3\0foo"
Pass Script should run with language="javascript1.4\0foo"
Pass Script should run with language="javascript1.5\0foo"
Pass Script should run with language="jscript\0foo"
Pass Script should run with language="livescript\0foo"
Pass Script should run with language="x-ecmascript\0foo"
Pass Script should run with language="x-javascript\0foo"
Pass Script shouldn't run with type=javascript (parser-inserted)
Pass Script shouldn't run with type=javascript1.0 (parser-inserted)
Pass Script shouldn't run with type=javascript1.1 (parser-inserted)
Pass Script shouldn't run with type=javascript1.2 (parser-inserted)
Pass Script shouldn't run with type=javascript1.3 (parser-inserted)
Pass Script shouldn't run with type=javascript1.4 (parser-inserted)
Pass Script shouldn't run with type=javascript1.5 (parser-inserted)
Pass Script shouldn't run with type=javascript1.6 (parser-inserted)
Pass Script shouldn't run with type=javascript1.7 (parser-inserted)
Pass Script shouldn't run with type=livescript (parser-inserted)
Pass Script shouldn't run with type=ecmascript (parser-inserted)
Pass Script shouldn't run with type=jscript (parser-inserted)

View file

@ -0,0 +1,141 @@
function testAttribute(attr, val, shouldRun) {
test(function() {
assert_false(window.ran, "ran variable not reset");
let script;
if (document.contentType === 'image/svg+xml') {
// SVG
script = document.createElementNS("http://www.w3.org/2000/svg", "script");
} else {
// HTML or XHTML
script = document.createElement("script");
}
script.setAttribute(attr, val);
script.textContent = "window.ran = true;";
document.querySelector('#script-placeholder').appendChild(script);
assert_equals(window.ran, shouldRun);
}, "Script should" + (shouldRun ? "" : "n't") + " run with " + attr + "=" +
format_value(val));
window.ran = false;
}
function testTypeShouldRun(type) {
testAttribute("type", type, true);
}
function testLanguageShouldRun(lang) {
testAttribute("language", lang, true);
}
function testTypeShouldNotRun(type) {
testAttribute("type", type, false);
}
function testLanguageShouldNotRunUnlessSVG(lang) {
// In SVGs, there is no concrete spec but all browsers agree that
// language attributes have no effects and thus script elements
// without type attributes are always expected to run regardless of
// language attributes.
const expectedToRun = document.contentType === 'image/svg+xml';
testAttribute("language", lang, expectedToRun);
}
// Unlike `test*()` methods above, there should be a (parser-inserted) script
// with an invalid type/language that would set `window.ran` to true just
// before `testParserInsertedDidNotRun()`, and
// `testParserInsertedDidNotRun()` asserts that the script did not run.
// `window.ran` should be reset where needed. For example:
// <script>window.ran = false;</script>
// <script type="invalid-type">window.ran = true;</script>
// <script>testParserInsertedDidNotRun('type=invalid-type');</script>
function testParserInsertedDidNotRun(description) {
test(() => assert_false(window.ran),
"Script shouldn't run with " + description + " (parser-inserted)");
window.ran = false;
}
// When prefixed by "application/", these match with
// https://mimesniff.spec.whatwg.org/#javascript-mime-type
const application = [
"ecmascript",
"javascript",
"x-ecmascript",
"x-javascript"
];
// When prefixed by "text/", these match with
// https://mimesniff.spec.whatwg.org/#javascript-mime-type
const text = [
"ecmascript",
"javascript",
"javascript1.0",
"javascript1.1",
"javascript1.2",
"javascript1.3",
"javascript1.4",
"javascript1.5",
"jscript",
"livescript",
"x-ecmascript",
"x-javascript"
];
const legacyTypes = [
"javascript1.6",
"javascript1.7",
"javascript1.8",
"javascript1.9"
];
const spaces = [" ", "\t", "\n", "\r", "\f"];
window.ran = false;
// Type attribute
testTypeShouldRun("");
testTypeShouldNotRun(" ");
application.map(t => "application/" + t).forEach(testTypeShouldRun);
application.map(t => ("application/" + t).toUpperCase()).forEach(
testTypeShouldRun);
spaces.forEach(function(s) {
application.map(t => "application/" + t + s).forEach(testTypeShouldRun);
application.map(t => s + "application/" + t).forEach(testTypeShouldRun);
});
application.map(t => "application/" + t + "\0").forEach(testTypeShouldNotRun);
application.map(t => "application/" + t + "\0foo").forEach(
testTypeShouldNotRun);
text.map(t => "text/" + t).forEach(testTypeShouldRun);
text.map(t => ("text/" + t).toUpperCase()).forEach(testTypeShouldRun);
legacyTypes.map(t => "text/" + t).forEach(testTypeShouldNotRun);
spaces.forEach(function(s) {
text.map(t => "text/" + t + s).forEach(testTypeShouldRun);
text.map(t => s + "text/" + t).forEach(testTypeShouldRun);
});
text.map(t => "text/" + t + "\0").forEach(testTypeShouldNotRun);
text.map(t => "text/" + t + "\0foo").forEach(testTypeShouldNotRun);
text.forEach(testTypeShouldNotRun);
legacyTypes.forEach(testTypeShouldNotRun);
// Language attribute
testLanguageShouldRun("");
testLanguageShouldNotRunUnlessSVG(" ");
text.forEach(testLanguageShouldRun);
text.map(t => t.toUpperCase()).forEach(testLanguageShouldRun);
legacyTypes.forEach(testLanguageShouldNotRunUnlessSVG);
spaces.forEach(function(s) {
text.map(t => t + s).forEach(testLanguageShouldNotRunUnlessSVG);
text.map(t => s + t).forEach(testLanguageShouldNotRunUnlessSVG);
});
text.map(t => t + "xyz").forEach(testLanguageShouldNotRunUnlessSVG);
text.map(t => "xyz" + t).forEach(testLanguageShouldNotRunUnlessSVG);
text.map(t => t + "\0").forEach(testLanguageShouldNotRunUnlessSVG);
text.map(t => t + "\0foo").forEach(testLanguageShouldNotRunUnlessSVG);

View file

@ -0,0 +1,37 @@
<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml">
<metadata>
<h:link rel="help" href="https://html.spec.whatwg.org/multipage/#scriptingLanguages" />
<h:link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script" />
</metadata>
<h:script src="../../../../resources/testharness.js"/>
<h:script src="../../../../resources/testharnessreport.js"/>
<h:div id="script-placeholder"/>
<h:script src="resources/script-type-and-language-js.js"/>
<script>window.ran = false;</script>
<script type="javascript">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript');</script>
<script type="javascript1.0">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.0');</script>
<script type="javascript1.1">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.1');</script>
<script type="javascript1.2">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.2');</script>
<script type="javascript1.3">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.3');</script>
<script type="javascript1.4">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.4');</script>
<script type="javascript1.5">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.5');</script>
<script type="javascript1.6">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.6');</script>
<script type="javascript1.7">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=javascript1.7');</script>
<script type="livescript">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=livescript');</script>
<script type="ecmascript">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=ecmascript');</script>
<script type="jscript">window.ran = true;</script>
<script>testParserInsertedDidNotRun('type=jscript');</script>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB