I have found that routes with dynamic paths through path processing are breaking under pathologic. For example, image styles.

The way these work is that a route is registered on a subfolder the public files directory path, then a path processor translates the trailing directory/filename into a query parameter which is in turn grabbed by the route controller. This is so that the subdirectory can have unlimited depth in the tree and still work.

For example:
My image style route is registered at /sites/default/files/styles/{image_style}/{scheme}
My image style url is /sites/default/files/styles/thumbnail/public/2016-05/myimage.jpg

When pathologic translates this url, the line:

$url = Url::fromUri('internal:/' . $url_params['path'], $url_params['options'])->toString();
returns:
/sites/default/files/styles/thumbnail/public

I'm assuming this is because that is the path that the actual route is registered on.

An easy solution would be to allow pathologic configuration to ignore paths. I actually found this bug when implementing a similar mechanism for caching external images.

Issue fork pathologic-2718473

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

acbramley created an issue. See original summary.

acbramley’s picture

Status: Active » Needs review
StatusFileSize
new6.31 KB

Adds an ignore_paths configuration item and checks this in the filter process callback.

acbramley’s picture

Status: Needs review » Needs work

The last submitted patch, 2: 2718473-ignore-paths-config-2.patch, failed testing.

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new7.68 KB

Attempting to fix test failures.

Status: Needs review » Needs work

The last submitted patch, 5: 2718473-ignore-paths-config-5.patch, failed testing.

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new7.91 KB

Had missed the schema updates for the filter settings.

Status: Needs review » Needs work

The last submitted patch, 7: 2718473-ignore-paths-config-7.patch, failed testing.

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new6.12 KB
new696 bytes

Updated to fix undefined index error if path was not set.

Status: Needs review » Needs work

The last submitted patch, 9: 2718473-ignore-paths-config-9.patch, failed testing.

acbramley’s picture

StatusFileSize
new7.2 KB

Woops, that included another patch.

jonathanshaw’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: 2718473-ignore-paths-config-11.patch, failed testing.

acbramley’s picture

I've tried to figure out where those tests are failing but I can't find what I'm missing. Any help would be great!

minoroffense’s picture

Status: Needs work » Needs review
StatusFileSize
new6.92 KB

Here's a reroll of the patch against the current dev. I can confirm that setting ignore paths for /sites/default/files/* fixes the image styles problem.

Status: Needs review » Needs work

The last submitted patch, 15: 2718473-ignore-paths-config-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

guedressel’s picture

This specific issue with image style URLs is only apparent when the image derivative is not yet created. Once the derivative is created (thus the derived image is available on the filesystem) pathologic does not screw up the path anymore.

guedressel’s picture

StatusFileSize
new918 bytes

Created patch checking non-file path via route-lookup if it is a image_style route.

guedressel’s picture

StatusFileSize
new917 bytes

Fixed my patch: internal:// is bad. internal:/ is better.

guedressel’s picture

StatusFileSize
new1.29 KB
new1.66 KB

Slightly improved version from #19 is now also integrated in #2418369-25: Internal URL handling (language prefixes, base://, ...).
To keep things together I attach this improved version also here.

dww’s picture

Issue tags: +Needs tests

Thanks for the bug report and all the effort so far! My goal is to get #2418369: Internal URL handling (language prefixes, base://, ...) in soon, since there are a lot of bugs in the queue related to that. But it'd be great to fix this, too.

Meanwhile, I'd like to make sure our test coverage is solid, so I'm not going to commit issues that don't have tests. Tagging for that.

Thanks again,
-Derek

dww’s picture

p.s. The title references all 'Dynamic routes' but my very quick skim of the patch and it looks like it's is hard-coded to only handle image style routes. If this is really only fixing image styles, let's update the title accordingly. If this is actually handling any other kinds of dynamic routes, can someone explain how that works? ;)

+        $cached_settings['is_file'] = $detected_route_name && strpos($detected_route_name, 'image.style_') === 0;

Thanks again,
-Derek

mvc’s picture

StatusFileSize
new1.59 KB

This patch works for me except that a language prefix is still inserted into the file path, since is_files is never actually used. I know that's not closely related to the original post here but I've added a snippet from the latest patch in #2418369: Internal URL handling (language prefixes, base://, ...) which solves that problem for me.

mvc’s picture

Title: Dynamic routes like image styles break under pathologic » Dynamic routes in image styles break under pathologic
mvc’s picture

StatusFileSize
new1.66 KB

Rerolling patch

veronicaseveryn’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

Rerolling for Pathologic 2.0.x branch

veronicaseveryn’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Added MR !17 on 2.0.x branch with the changes from #25 (without language piece)