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 url_converter.py using greedy regex to find URLs #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

codexterous
Copy link

The url_converters uses a greedy regex to find URLs, and can cause incorrect output. Here is a simple test case:

// SCSS
#features details {
  background: url("/static/profile/ui/img/asideicons.png") no-repeat;
}

@media (min-width: 768px) {
  #bodyContent {
    margin-top: 300px;
  }
}

// Output:
#features details{background:url("/static/profile/ui/img/asideicons.png") no-repeat}@media(min-width: 768px"){#bodyContent{margin-top:300px}}/*# sourceMappingURL=sass_bug_repro.css.map */

// Expected output:

#features details{background:url("/static/profile/ui/img/asideicons.png") no-repeat}@media(min-width: 768px){#bodyContent{margin-top:300px}}/*# sourceMappingURL=sass_bug_repro.css.map */

Note the stray double-quote character in media(min-width: 768px").

This happens because the repetition quantifier in the regex used is greedy, and runs all the way up until the very last ')' in the file. The solution is to use a lazy quantifier, which runs to the first ')' that it sees.

Note that this is an incomplete fix - regex is not suitable for parsing CSS, and this regex cannot parse things like:

url("file_\"with\"quotes_in_name.png") or
url("file (Copy).png")

For that, a real parser would be needed.

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.

1 participant