Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5693: CSS url parameter issue when it includes quotes #5694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/utils/resolve-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/resolveurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
:host {
background: url('foo.png');
}
.inline-svg {
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='4'/></svg>");
}
</style>
<img id="root" src$="[[rootPath]]foo.png">
<img id="import" src$="[[importPath]]foo.png">
Expand Down Expand Up @@ -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 xmlns='http:\/\/www.w3.org\/2000\/svg' width='10' height='10'><circle cx='5' cy='5' r='4'\/><\/svg>"\)/);
assert.match(el.$.import.getAttribute('src'), matchImport);
assert.match(el.$.root.getAttribute('src'), matchRoot);
document.body.removeChild(el);
Expand Down