$directory_path replacement to greedy

Created on 25 October 2024, 21 days ago

Problem/Motivation

When using this module with a remote stream wrapper configuration to passthroug images from another Drupal-Installation I hit the error that a image style is requested with the following URL:
https://content-repo.sge.local/sites/default/files/styles/drimage_improved_focal_1900_0/https/www.s-ge.com/sites/default/files/event/images/saudi_arabia_adobestock_215415863.jpg
As you can see there are two sites/default/files and the following code in DrimageSubscriber::onKernelRequest() will replace both of them:

      $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath();
      // Remove the directory path from the path.
      $path = str_replace('/' . $directory_path, '', $path);

Steps to reproduce

Easiest approach would be to create a file entity with a nested path that fits the public directory path.

Proposed resolution

Use a less greedy implementation that replaces only the first occurrence:

      // Remove only the first occurrence of the directory path.
      if (str_contains($path, '/' . $directory_path)) {
        $path = substr_replace($path, '', strpos($path, '/' . $directory_path), strlen('/' . $directory_path));
      }

Remaining tasks

  • ✅ File an issue
  • ➖ Addition/Change/Update/Fix
  • ➖ Testing to ensure no regression
  • ➖ Automated unit testing coverage
  • ➖ Automated functional testing coverage
  • ➖ UX/UI designer responsibilities
  • ➖ Readability
  • ➖ Accessibility
  • ➖ Performance
  • ➖ Security
  • ➖ Documentation
  • ➖ Code review by maintainers
  • ➖ Full testing and approval
  • ➖ Credit contributors
  • ➖ Review with the product owner
  • ➖ Release notes snippet
  • ❌ Release

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • N/A
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇭Switzerland das-peter

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