stage_file_proxy use_imagecache_root TRUE breaks image style generation for filenames containing dots

Created on 29 August 2025, about 1 month ago

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 getUriWithoutConvertedExtension() method 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.

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

Fix the getUriWithoutConvertedExtension() method in ImageStyleDownloadController to only remove extensions when there's evidence of actual image format conversion (e.g., image.png.jpg), not when filenames simply contain dots.
The fix involves:
Checking if both the current file extension AND the inner extension are valid image formats
Using Drupal's image factory service to determine supported extensions dynamically
Only removing the outer extension when both extensions are confirmed image types
This ensures that:
✅ image.png.jpg → image.png (actual conversion detected)
✅ image.jpg → image.jpg (no change, single extension)
✅ screenshot_2025-07-01_at_13.18.23.png → screenshot_2025-07-01_at_13.18.23.png (no change, dots in filename but no conversion)

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.

🐛 Bug report
Status

Active

Version

3.1

Component

Code

Created by

🇵🇱Poland piotr pakulski Poland 🇪🇺

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

Comments & Activities

Production build 0.71.5 2024