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

Fixed filter failure on unescaped urls #123

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

Fixed filter failure on unescaped urls #123

wants to merge 1 commit into from

Conversation

juniwalk
Copy link

Related #97

@juniwalk
Copy link
Author

@fprochazka Alright I am satisfied, could you check it out?

$self = $this;

return preg_replace_callback($regexp, function ($matches) use ($self, $file)
$regexp = '/url\(([\'"])?(.*)([\'"])?\)/i';
Copy link
Collaborator

Choose a reason for hiding this comment

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

this will fail when the url contains a newline character, or when there are two url statements on the same line :-/

Copy link
Author

Choose a reason for hiding this comment

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

I will look into it!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to fix the original regex

Copy link
Author

Choose a reason for hiding this comment

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

I am not that great with regexps and the original one looks like monstrosity, I like to do things the easy way, in this case I take anything in url() and work with in in PHP instead of doing everything in regexp.

@fprochazka
Copy link
Collaborator

It seems like you're solving three different issues at once, which is a bit confusing for me to review :-/

@juniwalk
Copy link
Author

What do you mean by three different issues?

// is already absolute
if (preg_match('/^([a-z]+:\/)?\//', $url)) {
// Skip absolute and data uris
if (preg_match('/^([a-z]+:|\/)/i', $url)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems like a separate issue

Copy link
Author

Choose a reason for hiding this comment

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

This is just extension, I removed data uri filtering from the regexp so I filter it here.

@juniwalk
Copy link
Author

@fprochazka I've fixed the greedines but I can't remove the trim nor undo the modification of the condition. If you wan't I can split this code into several commits.

@@ -55,7 +55,7 @@ public function setBasePath($basePath)
public function absolutizeUrl($url, $quote, $cssFile)
{
// is already absolute
if (preg_match('/^([a-z]+:\/)?\//', $url)) {
if (preg_match('/^([a-z]+:|\/)/i', $url)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you think you could add some more tests for this method, so it's obviouse what you were tryting to solve?

Copy link
Author

Choose a reason for hiding this comment

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

What exactly would you want? Paths from all urls are passed into this match, if it is https? or data uri, it is returned as is, if not, the path is then parsed further.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like some unit tests for this method only.

Copy link
Author

Choose a reason for hiding this comment

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

I've added 2 assertions into testAbsolutizeAbsolutized, should be sufficient.

@juniwalk
Copy link
Author

@fprochazka You were right, this pull is starting to get little big. Too bad there weren't more tests for this filter in the first place, this would have been much easier.

@juniwalk
Copy link
Author

juniwalk commented Mar 7, 2016

@fprochazka ping, probably busy, right?

@fprochazka
Copy link
Collaborator

@juniwalk I'm scared of the regexp changes, I'm gonna have to dive into it and verify it works as expected - which will take time :)

@juniwalk
Copy link
Author

juniwalk commented Mar 8, 2016

@fprochazka I see, I hoped to cover this in the style.css --> style.css.expected test case, anyway if you need me to add more cases or change something just let me know.

@juniwalk
Copy link
Author

@fprochazka Hello, any news? I've spent last hour finding one issue only to discover that it is this issue with webloader again.

@fprochazka
Copy link
Collaborator

fprochazka commented Apr 19, 2016

Sorry, no time for this so far.

@juniwalk
Copy link
Author

I've redirected composer to my cloned copy so I use the changes I've made. It's okay for now but not ideal.

@juniwalk
Copy link
Author

@fprochazka Hello, still no time? Last commit was 7 months ago, looks like this repo is being "abandoned" :/

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.

2 participants