Bug 1277534 - avoid output-parser failure with invalid URL; r=pbro, a=lizzard
authorTom Tromey <tom@tromey.com>
Mon, 06 Jun 2016 08:56:47 -0600
changeset 339775 19de2d70cf3ff501837ea13a3803e31d8e54b259
parent 339774 cea38bcafb6ad58462496b582cec8eb361a727df
child 339776 6084507f9104e2fea2e61c3b9b11f569628851f8
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro, lizzard
bugs1277534
milestone49.0a2
Bug 1277534 - avoid output-parser failure with invalid URL; r=pbro, a=lizzard MozReview-Commit-ID: CK5n8sHgmwD
devtools/client/shared/output-parser.js
devtools/client/shared/test/browser_outputparser.js
--- a/devtools/client/shared/output-parser.js
+++ b/devtools/client/shared/output-parser.js
@@ -523,17 +523,21 @@ OutputParser.prototype = {
       // seemed simpler on the whole.
       let [, leader, , body, trailer] =
         /^(url\([ \t\r\n\f]*(["']?))(.*?)(\2[ \t\r\n\f]*\))$/i.exec(match);
 
       this._appendTextNode(leader);
 
       let href = url;
       if (options.baseURI) {
-        href = new URL(url, options.baseURI).href;
+        try {
+          href = new URL(url, options.baseURI).href;
+        } catch (e) {
+          // Ignore.
+        }
       }
 
       this._appendNode("a", {
         target: "_blank",
         class: options.urlClass,
         href: href
       }, body);
 
--- a/devtools/client/shared/test/browser_outputparser.js
+++ b/devtools/client/shared/test/browser_outputparser.js
@@ -1,15 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-var {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js",
-                         {});
 var {OutputParser} = require("devtools/client/shared/output-parser");
 
 add_task(function* () {
   yield addTab("about:blank");
   yield performTest();
   gBrowser.removeCurrentTab();
 });
 
@@ -211,33 +209,41 @@ function testParseURL(doc, parser) {
     },
     {
       desc: "bad url, missing paren",
       leader: "url(",
       trailer: "",
       expectedTrailer: ")"
     },
     {
+      desc: "bad url, missing paren, with baseURI",
+      baseURI: "data:text/html,<style></style>",
+      leader: "url(",
+      trailer: "",
+      expectedTrailer: ")"
+    },
+    {
       desc: "bad url, double quote, missing paren",
       leader: "url(\"",
       trailer: "\"",
       expectedTrailer: "\")",
     },
     {
       desc: "bad url, single quote, missing paren and quote",
       leader: "url('",
       trailer: "",
       expectedTrailer: "')"
     }
   ];
 
   for (let test of tests) {
     let url = test.leader + "something.jpg" + test.trailer;
     let frag = parser.parseCssProperty("background", url, {
-      urlClass: "test-urlclass"
+      urlClass: "test-urlclass",
+      baseURI: test.baseURI,
     });
 
     let target = doc.querySelector("div");
     target.appendChild(frag);
 
     let expectedTrailer = test.expectedTrailer || test.trailer;
 
     let expected = test.leader +