Filenames with period do not match in the PathProcessor when validating images

Created on 7 July 2025, 5 days ago

Problem/Motivation

If the image filename has a period in it like "somefile.portrait.jpg" the period get replaced with double underscore "somefile__portrait__jpg" but on the PathProcessor the validation is against the filename without the double underscore

        // Ensure Crop Target and Requested Image are the same.
        $path_parts = pathinfo($crop_uri);
        $crop_target_filename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '__' . $path_parts['extension'];
        if ($original_image_path != $crop_target_filename) {
          throw new NotFoundHttpException();
        }

Steps to reproduce

Add an image with a period in the file name

Proposed resolution

Not sure if it's best to change the MediaContextualCropService class to not transform the period and to leave it or to transform the period in the PathProcessorImageStyles class to convert the file name to have the double underscore. I propose to update PathProcessorImageStyles as it is simpler

        // Ensure Crop Target and Requested Image are the same.
        $path_parts = pathinfo($crop_uri);
        $crop_target_filename = $path_parts['dirname'] . '/' . str_replace('.', '__', $path_parts['filename']) . '__' . $path_parts['extension'];
        if ($original_image_path != $crop_target_filename) {
          throw new NotFoundHttpException();
        }
🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇨🇦Canada erichomanchuk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024