From c9f36f2ac66776b494093aa6fda5138dc35823a0 Mon Sep 17 00:00:00 2001 From: jpradelle Date: Thu, 7 Oct 2021 16:25:23 +0200 Subject: [PATCH] Fix #5693: CSS url parameter issue when it includes quotes --- lib/utils/resolve-url.js | 4 ++++ test/unit/resolveurl.html | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/utils/resolve-url.js b/lib/utils/resolve-url.js index 5dd89cbcf2..f60e139151 100644 --- a/lib/utils/resolve-url.js +++ b/lib/utils/resolve-url.js @@ -77,6 +77,10 @@ export function resolveUrl(url, baseURI) { */ export function resolveCss(cssText, baseURI) { return cssText.replace(CSS_URL_RX, function(m, pre, url, post) { + // No resolution for data: urls + if (url.match(/^["']?data:/)) { + return pre + url + post; + } return pre + '\'' + resolveUrl(url.replace(/["']/g, ''), baseURI) + '\'' + post; diff --git a/test/unit/resolveurl.html b/test/unit/resolveurl.html index 2ce6c8b27f..99c3d71f0e 100644 --- a/test/unit/resolveurl.html +++ b/test/unit/resolveurl.html @@ -30,6 +30,9 @@ :host { background: url('foo.png'); } + .inline-csv { + background: url("data:image/svg+xml;utf8,"); + } @@ -125,6 +128,7 @@ var matchImport = /defineImport\//i; var style = el.shadowRoot.querySelector('style') || document.querySelector('style[scope=x-late]'); assert.match(style.textContent, matchImport); + assert.match(style.textContent, /url\("data:image\/svg\+xml;utf8,<\/svg>"\)/); assert.match(el.$.import.getAttribute('src'), matchImport); assert.match(el.$.root.getAttribute('src'), matchRoot); document.body.removeChild(el);