-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: escape double quote of url value in CSS url()
#7718
Fix: escape double quote of url value in CSS url()
#7718
Conversation
|
@@ -83,7 +83,8 @@ export default (new Transformer({ | |||
symbols: new Map([['*', {local: '*', isWeak: true, loc}]]), | |||
}); | |||
} else if (dep.type === 'url') { | |||
asset.addURLDependency(dep.url, { | |||
// if dependency imported with url() includes ", escape " double quotes because this url value will be enclosed with double quote " | |||
asset.addURLDependency(dep.url.replace(/"/g, '\\"'), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I think this might cause an issue for resolvers because they won't expect pre-escaped values. Perhaps this replacement should be done in the packager. The util here is what does the replacement of placeholders to resolved urls. It might need an option to escape the url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, indeed. As you say, escaping the background image’s URL in Transformer will cause the not found error in resolver. I will fix this 👍 Thank you for your advice!
I think escaping the quote in URL is needed in anyway because
- if URL is not enclosed with quotes, it is not a valid property that the quote exists in the URL
- if URL is enclosed with quotes, the quote should be escaped
#7564 as you can see in this PR, I think we need to enclose the URL in quotes and then escape the quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this issue, and I notice that parcel's resolver cannot resolve the filepath of the image where the quotes are escaped though such a URL is the correct URL in the first place. So I think escape should be done with CSSTransformer and the resolver should be modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about making the resolver able to handle escaped quotes, but I was concerned about performance degradation due to increased computation, so I made a change to remove escaped quotes from URLs with the CSSTransformer and re-escape them with the CSSPackager. ea56294
7e8ae38
to
ea56294
Compare
6980ae3
to
0e3f3bd
Compare
0e3f3bd
to
483258c
Compare
placeholder: dep.placeholder, | ||
asset.addURLDependency( | ||
// when URL is escaped, parcel resolver cannot resolve URL, so we need to unescape it in transformer | ||
dep.url.replace(/\\"/g, '"').replace(/\\'/g, "'"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary. The url will already be unescaped before it is passed to us.
Thanks for getting this started @Shinyaigeek! I refactored it a little so that we handle the escaping differently depending on the asset type. For example, in HTML, quotes become |
Thank you for your help @devongovett !! I saw your commit, and feels reasonable. Sure, escaping only CSS text was short-circuited and should have been able to escape other files in the parcel pipeline! I learned a lot from that 👍 |
* upstream/v2: Upgrade Flow to 0.174.1 (#7849) v2.4.0 v2.4.0 changelog Bump Parcel CSS Dynamic imports priority fix closes #6980 (#7061) fix(transformers): errors.map is not a function (#7672) Make NodeResolver check realpath before resolving with `source` entry (#7846) docs: fix wrong location documents (#7689) Fix: escape double quote of url value in CSS `url()` (#7718) Update @parcel/css and add diagnostic for url dependencies in custom properties (#7845) Use relative path for bundle labels in bundle analysis (#7737) Allow use react-jsx transform in React 16.14.0 (#7728) Move to @parcel/css by default (#7821) Feature: pick PORT number also from .env file (#7819) Enable parsing static initialization blocks (#7839) Bump swc and prevent pure comment removal (#7833) Bump swc (#7777) Human readable file size in bundle analyzer report (#7766) Improve emoji support detection (#7775)
Fixes: #7710
↪️ Pull Request
Hi team! 👋
In css transforming,
CSSTransformer
encloses URL value in CSSurl()
with"
double quote, so I fixed this simply by escaping”
double quote in url value inurl()
, but honestly I'm worried that this way is too straightforward and I overlooked some context.If there is something I missed, please be free to point out or close this PR 🙇
💻 Examples
🚨 Test instructions
simply, I checked with the case base64 encoded url value with
"
✔️ PR Todo