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

customCSS URL rewriting exemption-check is broken #266

Closed
rjgotten opened this issue Feb 28, 2018 · 2 comments
Closed

customCSS URL rewriting exemption-check is broken #266

rjgotten opened this issue Feb 28, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@rjgotten
Copy link

rjgotten commented Feb 28, 2018

URLs rewritten inside customCSS have an exemption list, but it is incomplete and in part broken.

Current exemption logic is:

if (
  !src_path.startsWith('http') &&
  !src_path.startsWith('//') &&
  !src_path.startsWith('data:')
) {
  // ...
}

This has two problems:

  • It fails to rewrite relative urls such as url("http_foo/bar.jpg") which are most definitely relative, because the starting check for HTTP is overly naive.
  • It mistakingly rewrites domain-relative paths such as url("/foo/bar.jpg"), because it fails to detect them outright.

You can cover all the necessary cases with a simple regex, afaict:

let regNoRewrite = /^(?:https?\:|data\:|\/)/i;
if ( !regNoRewrite.test(src_path)) {
  // ...
}
@jgerigmeyer
Copy link
Member

Good catch! As I said over on #265: a PR (with tests) would be welcome; otherwise I'll try to get to this in the next week.

@jgerigmeyer
Copy link
Member

@rjgotten Would you be willing to try against the master branch and see if this is adequately fixed? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants