## Problem/Motivation
When Stage File Proxy attempts to fetch image style derivatives with query parameters (e.g., `?itok=...`), the `pathinfo()` function in `DownloadManager::fetchResponse()` incorrectly treats the query string as part of the file extension. This causes the module to request malformed URLs from the origin server, resulting in 404 errors.
**Example scenario:**
- Original request: `styles/medium/public/2024-01/liitu-uusi-asiakas-oikea-2.1.24.jpg?itok=WGoLZcyu`
- Expected fetch URL: `https://example.com/sites/default/files/2024-01/liitu-uusi-asiakas-oikea...`
- Actual fetch URL: `https://example.com/sites/default/files/2024-01/liitu-uusi-asiakas-oikea...` (missing `.24.jpg`)
The bug occurs because `pathinfo()` on line 126 of `src/DownloadManager.php` receives a path with query parameters, causing it to misidentify the file extension as `jpg?itok=WGoLZcyu` instead of `jpg`. This is particularly problematic for filenames containing dots (e.g., version numbers like `2.1.24`).
### Steps to reproduce
1. Enable Stage File Proxy module (version 3.1.6)
2. Configure origin server URL in settings.php
3. Upload an image with dots in the filename (e.g., `my-file-2.1.24.jpg`)
4. Request an image style derivative of this file (e.g., `/styles/medium/public/...`)
5. Observe the error in watchdog logs:
Stage File Proxy encountered an error when retrieving file https://example.com/sites/default/files/2024-01/my-file-2.1.24.
Client error: GET https://example.com/sites/default/files/2024-01/my-file-2.1?itok=... resulted in a 404 Not Found
## Proposed resolution
Strip query parameters from `$relative_path` before calling `pathinfo()` in the `fetchResponse()` method. The query parameters should be removed only for the purpose of path parsing, not from the actual request URL.
**Code change in `src/DownloadManager.php` (line 126):**
```php
// Before:
$path_info = pathinfo($relative_path);
// After:
// Strip query parameters before calling pathinfo() to avoid treating
// them as part of the file extension.
$path_without_query = preg_replace('/\?.*$/', '', $relative_path);
$path_info = pathinfo($path_without_query);
A patch implementing this fix is attached.
| Comment | File | Size | Author |
|---|---|---|---|
| stage_file_proxy-pathinfo-query-params.patch | 1.01 KB | tormi |
Comments
Comment #2
tormiBTW, D.O issues really should start using markdown format.
Comment #3
tormiComment #4
smustgrave commentedFixes need to be in MRs please.
Possible to get any test coverage.
Comment #5
smustgrave commentedComment #6
smustgrave commentedPotential duplicate? #3574729: Image style derivatives broken for filenames with multiple dots
Comment #7
smustgrave commentedIf still an issue please re-open.