Problem/Motivation

When stage_file_proxy module is configured with use_imagecache_root: true, image style generation fails for files with filenames containing dots (e.g., screenshot_2025-07-01_at_13.18.23.png). The issue occurs because the module relies on Drupal core's ImageStyleDownloadController::getUriWithoutConvertedExtension() method, which incorrectly removes file extensions when filenames contain dots, treating them as converted image extensions even when they're not.
The problem manifests as broken image styles in local development environments where stage_file_proxy is used to proxy files from production. Images with simple names work fine, but images with timestamps, version numbers, or other dot-separated elements in the filename fail to generate resized/styled versions.
This is caused by a bug in Drupal core's getUriWithoutConvertedExtension() method, but since core doesn't typically use this method with user-uploaded filenames, the bug only surfaces when stage_file_proxy calls it.

Steps to reproduce

1.Configure stage_file_proxy module with use_imagecache_root: true
2. Upload an image with dots in the filename (e.g., screenshot_2025-07-01_at_13.18.23.png)
3. Try to access an image style (e.g., /sites/default/files/styles/thumbnail/public/screenshot_2025-07-01_at_13.18.23.png)
4. Observe that the styled image is not generated and shows as broken image
5. Upload an image without dots in filename (e.g., screenshot20250701at131823.png)
6. Observe that this image's styles work correctly

Proposed resolution

Add validation to the stage_file_proxy module to verify that the result from getUriWithoutConvertedExtension() is actually a valid image file before using it. This prevents the module from trying to fetch non-existent "converted" files when the core method incorrectly strips extensions from filenames with dots.
The fix involves:
Adding ImageFactory service injection to StageFileProxySubscriber
Checking if the extension of the "unconverted" path is actually a supported image format
Only using the unconverted path if it has a valid image extension
This ensures that:
✅ image.png.jpg → tries to fetch image.png (valid image extension)
✅ image.jpg → no change (single extension)
✅ screenshot_2025-07-01_at_13.18.23.png → doesn't try to fetch invalid screenshot_2025-07-01_at_13.18 (no valid extension)
Note: This is a workaround for a bug in Drupal core's ImageStyleDownloadController::getUriWithoutConvertedExtension() method. The core method should be fixed separately, but this patch provides immediate relief for stage_file_proxy users.

Remaining tasks

User interface changes

None. This is a backend fix that resolves broken image display but doesn't change any user interfaces.

API changes

None. The getUriWithoutConvertedExtension() method signature remains the same, only the internal logic is improved.

Data model changes

None. This fix only affects the logic for determining original file paths from image style URLs.

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

piotr pakulski created an issue. See original summary.

piotr pakulski’s picture

Issue summary: View changes

piotr pakulski’s picture

Issue summary: View changes
piotr pakulski’s picture

Assigned: piotr pakulski » Unassigned
Status: Active » Needs review

This is a workaround for a bug in Drupal core's ImageStyleDownloadController::getUriWithoutConvertedExtension() method. The core method should be probably fixed separately, but this patch provides immediate relief for stage_file_proxy users. I'm not sure if worth fighting with the core... we may decide if we just want to merge the fix into stage file proxy module.

smustgrave’s picture

Status: Needs review » Needs work

Let’s add some kind of test coverage

smustgrave’s picture

Version: 3.1.x-dev » 4.0.x-dev
Status: Needs work » Fixed

Will include in the 4.0.x release I want to do soon.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • smustgrave committed 57654aff on 4.0.x
    Issue #3543794: Fix image style generation for filenames with multiple...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.