Bug 1551816 - Bail out rendering urls in rule-view if they're not valid; r=gl
authorPatrick Brosset <pbrosset@mozilla.com>
Thu, 16 May 2019 14:54:07 +0000
changeset 532946 72820b3eb2f053dde3339ec9679139b9dd78df4a
parent 532945 2925cfa3e8c3577f427c28e1c36ee6fb69393b94
child 532947 787463261cbf1aa187584ca5d12a634ef61bfc8c
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1551816
milestone68.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 1551816 - Bail out rendering urls in rule-view if they're not valid; r=gl Differential Revision: https://phabricator.services.mozilla.com/D31230
devtools/client/inspector/shared/test/browser_styleinspector_output-parser.js
devtools/client/shared/output-parser.js
--- a/devtools/client/inspector/shared/test/browser_styleinspector_output-parser.js
+++ b/devtools/client/inspector/shared/test/browser_styleinspector_output-parser.js
@@ -286,16 +286,24 @@ const TEST_DATA = [
   },
   {
     name: "background",
     value: "rgb(255, var(--g-value, 0), 192)",
     test: fragment => {
       is(fragment.textContent, "rgb(255, var(--g-value, 0), 192)");
     },
   },
+  {
+    name: "--url",
+    value: "url(())",
+    test: fragment => {
+      is(countAll(fragment), 0);
+      is(fragment.textContent, "url(())");
+    },
+  },
 ];
 
 add_task(async function() {
   // Mock the toolbox that initCssProperties expect so we get the fallback css properties.
   const toolbox = {
     target: {
       client: {},
       hasActor: () => false,
--- a/devtools/client/shared/output-parser.js
+++ b/devtools/client/shared/output-parser.js
@@ -1335,18 +1335,25 @@ OutputParser.prototype = {
       // "as-authored", but it makes a bit more sense.
       match = this._sanitizeURL(match);
       // This regexp matches a URL token.  It puts the "url(", any
       // leading whitespace, and any opening quote into |leader|; the
       // URL text itself into |body|, and any trailing quote, trailing
       // whitespace, and the ")" into |trailer|.  We considered adding
       // functionality for this to CSSLexer, in some way, but this
       // seemed simpler on the whole.
-      const [, leader, , body, trailer] =
-        /^(url\([ \t\r\n\f]*(["']?))(.*?)(\2[ \t\r\n\f]*\))$/i.exec(match);
+      const urlParts = /^(url\([ \t\r\n\f]*(["']?))(.*?)(\2[ \t\r\n\f]*\))$/i.exec(match);
+
+      // Bail out if that didn't match anything.
+      if (!urlParts) {
+        this._appendTextNode(match);
+        return;
+      }
+
+      const [, leader, , body, trailer] = urlParts;
 
       this._appendTextNode(leader);
 
       let href = url;
       if (options.baseURI) {
         try {
           href = new URL(url, options.baseURI).href;
         } catch (e) {