Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@jackw
Copy link
Contributor

@jackw jackw commented Aug 8, 2023

This PR addresses the issue of undefined being concatenated into url strings when urls aren't wrapped in quotes.

I believe the fixture css I've added is valid for urls. I've not used chomp before. It changed some dist files when I ran it locally but I'm guessing you wouldn't want me to commit these changes in the PR. 🤔

fixes: #2460

.then(function (source) {
source = source.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g, function (match, quotes, relUrl1, relUrl2) {
return 'url(' + quotes + resolveUrl(relUrl1 || relUrl2, url) + quotes + ')';
return ['url(', quotes, resolveUrl(relUrl1 || relUrl2, url), quotes, ')'].join('');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain the bug that this is resolving? This refactoring looks entirely equivalent to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I should have probably added the following to the PR description...

It's valid CSS to not include quotes in urls like background-image: url(my/image.png);. However the code above that tries to resolve urls doesn't seem to cater for this. So if quotes is undefined the string concatenation adds undefined to the result and the image fails to load. e.g.

'url(' + undefined + 'my/image.png' + undefined + ')' // --> "url(undefinedmy/image.pngundefined)"

However using array.join we can take advantage of the spec to discard unwanted undefined from the result.

If element0 is undefined or null, let R be the empty String; otherwise, Let R be ToString(element0).

e.g.

['url(', undefined, 'my/image.png', undefined, ')'].join('') // --> "url(my/image.png)" 

I'm more than happy to refactor if you feel the approach I've taken isn't explicit enough.

@guybedford
Copy link
Member

Thanks for clarifying, makes sense now!

@guybedford guybedford merged commit 61bc72f into systemjs:main Aug 16, 2023
@JennerChen
Copy link

JennerChen commented Dec 23, 2023

@guybedford latest version 6.14.2 still not working. maybe need release new one.
system.min.js still use old one
image
https://g.alicdn.com/code/lib/systemjs/6.14.2/system.min.js

system.js is correct
image
https://g.alicdn.com/code/lib/systemjs/6.14.2/system.js

@jackw jackw deleted the jackw/fix-css-url-quotes branch November 11, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

systemjs load css suport url(image/test.svg) without quotes in url

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.