Bug 1428745 - Remove support for version parameter from script loader - trimming script type, r=jonco
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 09 Jan 2018 17:00:50 +0100
changeset 450275 ce14f861f1a8139c7e94b7aa171ec6b0d3808cbf
parent 450274 0908d28cbd852627017fcb3a0b0ed056575308a1
child 450276 d5f42a23909eb181274731b07e4984bfbd18557d
child 450352 6c6f3fd9c5e114a1cb0ebb7fb5c19933954e94dd
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>