Bug 1428745 - Remove support for version parameter from script loader - trimming script type, r=jonco
☠☠ backed out by 38614ffd21d1 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 09 Jan 2018 17:00:50 +0100
changeset 450248 1d975770bd9a19208fb84e306729e5ce1ee396fc
parent 450247 1d5dc7dfd429af246a1d1aa1854485be1ad4b6ab
child 450249 3fc0bcaa2ce2ae65832c810d2b2b6990fff81c8b
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1428745
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1428745 - Remove support for version parameter from script loader - trimming script type, r=jonco
dom/html/HTMLScriptElement.cpp
dom/tests/mochitest/script/mochitest.ini
dom/tests/mochitest/script/test_whitespace.html
--- a/dom/html/HTMLScriptElement.cpp
+++ b/dom/html/HTMLScriptElement.cpp
@@ -166,19 +166,30 @@ HTMLScriptElement::SetText(const nsAStri
 {
   aRv = nsContentUtils::SetNodeTextContent(this, aValue, true);
 }
 
 // variation of this code in nsSVGScriptElement - check if changes
 // need to be transfered when modifying
 
 bool
-HTMLScriptElement::GetScriptType(nsAString& type)
+HTMLScriptElement::GetScriptType(nsAString& aType)
 {
-  return GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
+  nsAutoString type;
+  if (!GetAttr(kNameSpaceID_None, nsGkAtoms::type, type)) {
+    return false;
+  }
+
+  // ASCII whitespace https://infra.spec.whatwg.org/#ascii-whitespace:
+  // U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020 SPACE.
+  static const char kASCIIWhitespace[] = "\t\n\f\r ";
+  type.Trim(kASCIIWhitespace);
+
+  aType.Assign(type);
+  return true;
 }
 
 void
 HTMLScriptElement::GetScriptText(nsAString& text)
 {
   IgnoredErrorResult rv;
   GetText(text, rv);
 }
--- a/dom/tests/mochitest/script/mochitest.ini
+++ b/dom/tests/mochitest/script/mochitest.ini
@@ -1,6 +1,7 @@
 [DEFAULT]
 support-files =
   file_blocked_script.sjs
 
 [test_bug1053321.html]
 skip-if = os == 'android' # bug 1386644
+[test_whitespace.html]
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/script/test_whitespace.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for ScriptLoader and type with whitespaces</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript">
+let passed = false;
+
+let tests = [
+  [ " application/javascript", true ],
+  [ "\tapplication/javascript\n\r \t", true ],
+];
+
+for (let i = 0; i < tests.length; ++i) {
+  passed = false;
+
+  let script = document.createElement('script');
+  script.setAttribute('type', tests[i][0]);
+  script.innerText = "passed = true;";
+  document.body.appendChild(script);
+
+  ok (passed, tests[i][1], "Test " + tests[i][0] + " passed");
+}
+</script>
+
+</body>
+</html>