Problem/Motivation
For image style derivatives,
FlysystemStreamWrapper::getExternalUrl() routes the URL back
through Drupal:
$dir_path = $this->getPublicDirectoryPath(); if ($dir_path !== NULL) { $base = rtrim($this->getDrupalBaseUrl(), '/'); return $base . '/' . $dir_path . '/' . $target; }
The NULL check is not enough: getPublicDirectoryPath() returns
'' (not NULL) when the public scheme's
public_url_base has no path component — a bare CDN or bucket
domain. The result contains a double slash:
https://example.com//styles/large/public/foo.jpg.
Once file_url_transform_relative() strips the base off, the
markup contains //styles/large/public/foo.jpg, which browsers
parse as protocol-relative: the host becomes styles and the image
never loads.
This affects both branches that build a Drupal-routed derivative URL (the
CloudFront branch and the generic non-local adapter branch).
Steps to reproduce
-
Configure a Flysystem scheme whose
public_url_baseis a bare
domain (no path), used forpublic://. - Render any image with an image style.
-
Inspect the markup:
src="//styles/...", image 404s / resolves
against the wrong host.
Proposed resolution
Only insert the directory path segment when it is non-empty:
return $dir_path !== '' ? $base . '/' . $dir_path . '/' . $target : $base . '/' . $target;
Remaining tasks
- Review.
-
Unit coverage in
FlysystemStreamWrapperTestwith
getPublicDirectoryPath()returning''.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| flysystem-05-external-url-double-slash.patch | 1.57 KB | luigisa |
Issue fork flysystem-3616491
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:
- 3616491-getexternalurl-returns-a
changes, plain diff MR !120
Comments
Comment #4
lisa.rae commentedPostponing any review of the MR on this issue pending review and acceptance of the MR on the related issue, https://www.drupal.org/project/flysystem/issues/3616488
Comment #5
lisa.rae commentedComment #6
luigisa commentedClosing as duplicate of #3616488.
The empty public-directory-path guard in FlysystemStreamWrapper::getExternalUrl()
(and the matching unit tests) already landed in 3.0.x via 3e8d16a as part of
that issue. Rebasing this MR onto current 3.0.x leaves an empty diff.
MR !120 can be closed without merging.
Comment #8
lisa.rae commentedThank you!