Bug 1548306 - Do not allow the ^ character to appear in the hostname. r=mayhemer, a=jcristau
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 04 Jun 2019 13:35:47 +0000
changeset 536797 33d0d344ea16b9219b36d922fe45549c29326e6a
parent 536796 12ee297149424a925bb820705b417d28ae57ce06
child 536798 1176df94118f3b4957e4f0851995e34bbb137774
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer, jcristau
bugs1548306
milestone68.0
Bug 1548306 - Do not allow the ^ character to appear in the hostname. r=mayhemer, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D32895
dom/quota/test/unit/test_originWithCaret.js
netwerk/base/nsStandardURL.cpp
--- a/dom/quota/test/unit/test_originWithCaret.js
+++ b/dom/quota/test/unit/test_originWithCaret.js
@@ -1,15 +1,13 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+"use strict";
+
 async function testSteps() {
-  const principal = getPrincipal("http://example.com^123");
-
-  try {
+  Assert.throws(() => {
+    const principal = getPrincipal("http://example.com^123");
     getSimpleDatabase(principal);
-    ok(false, "Should have thrown");
-  } catch (ex) {
-    ok(true, "Did throw");
-  }
+  }, /NS_ERROR_MALFORMED_URI/, "^ is not allowed in the hostname");
 }
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -64,16 +64,17 @@ bool nsStandardURL::gPunycodeHost = true
 // so we do not need to "optimize" TestForInvalidHostCharacters.
 //
 constexpr bool TestForInvalidHostCharacters(char c) {
   // Testing for these:
   // CONTROL_CHARACTERS " #/:?@[\\]*<>|\"";
   return (c > 0 && c < 32) ||  // The control characters are [1, 31]
          c == ' ' || c == '#' || c == '/' || c == ':' || c == '?' || c == '@' ||
          c == '[' || c == '\\' || c == ']' || c == '*' || c == '<' ||
+         c == '^' ||
 #if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE)
          // Mailnews %-escapes file paths into URLs.
          c == '>' || c == '|' || c == '"';
 #else
          c == '>' || c == '|' || c == '"' || c == '%';
 #endif
 }
 constexpr ASCIIMaskArray sInvalidHostChars =