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: Correctly process urls when they are rewritten to contain space #7452

Merged
merged 3 commits into from Mar 27, 2022

Conversation

Artur-
Copy link
Contributor

@Artur- Artur- commented Mar 25, 2022

Description

If a CSS file contains

background: url(folder/foo.png)

and the processing of the URL causes "folder" to be rewritten to e.g. "other folder", then the end result cannot be

background: url(other folder/foo.png)

because using space without wrapping the url with ' or " is not allowed.

This rewrites the url in this case to

background: url('other folder/foo.png')

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

If a CSS file contains

background: url(folder/foo.png)

and the processing of the URL causes "folder" to be rewritten to e.g. "other folder", then the end result cannot be

background: url(other folder/foo.png)

because using space without wrapping the url with ' or " is not allowed.

This rewrites the url in this case to

background: url('other folder/foo.png')
@Artur-
Copy link
Contributor Author

Artur- commented Mar 26, 2022

I wonder if this could break if used inside JS, inside a string using '.... The other approach would be to not wrap but instead encode the url, this would not break because of the wrapping but could it accidentally double encode in some cases?

@patak-dev
Copy link
Member

I wonder if this could break if used inside JS, inside a string using '.... The other approach would be to not wrap but instead encode the url, this would not break because of the wrapping but could it accidentally double encode in some cases?

I thought the same when reviewing the PR, it would require checking where this needs to be decoded afterward. I think we could merge this as a first step, and it would be interesting if you could generate a failing test to justify going further and encode/decode

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

LGTM. Re space encoding, perhaps it's related to #7305, but I haven't fully understand if that PR is safe yet.

@patak-dev patak-dev merged commit 9ee2cf6 into vitejs:main Mar 27, 2022
@Artur-
Copy link
Contributor Author

Artur- commented Mar 29, 2022

It would be interesting if you could generate a failing test to justify going further and encode/decode

I tried to do this but either everything is ok or I did not manage to find the failing combination. Maybe it will show up later...
Instead I hit #7510

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.

None yet

3 participants