Problem/Motivation
file_url_transform_relative($file_url) function might need to perform additional check on a file URL port:
Steps to reproduce
On one of ours development environments we are using s3 storage, that is under the same host with the drupal site, but having different port. (like drupal is accessible at http://example.com and s3 storage under http://example.com:9000)
Since file_url_transform_relative preg match doesn't count in file url ports and all the absolute paths were transformed to relative with port in the beginning ":9000/{{some image path}}" and broken.
Proposed resolution
I've resolved this issue by adding next lines (patch attached):
$file_url_port = parse_url($file_url, PHP_URL_PORT) ?? $port;
if ($file_url_port != $port) {
return $file_url;
}
Maybe someone will find this useful.
Comment | File | Size | Author |
---|---|---|---|
#9 | 3174349-9.patch | 2.92 KB | quietone |
#9 | interdiff-5-9.txt | 1.61 KB | quietone |
#5 | 3174349-5.patch | 2.84 KB | quietone |
#5 | 3174349-5-fail.patch | 2.23 KB | quietone |
file_url_transform_relative_additional_port_check.patch | 662 bytes | itaran | |
Comments
Comment #3
Kristen PolThanks for the issue and patch. Moving back to needs work for a test.
Comment #4
Kristen PolComment #5
quietone CreditAttribution: quietone as a volunteer commentedAdded a test, thanks to guidance from dww on #bugsmash.
There is no interdiff because this is so small.
Comment #7
dwwYay, thanks for working on this. Glad my Slack comments were helpful. ;)
I'm a little reluctant to NW for this review, since it's mostly a reflection of my own confusion. But perhaps we could update the comments to help others make sense of it all?
See below -- I don't think "unique" clarifies the bug here. I was confused until I read the patch and the surrounding code twice.
That's weird, looks like we already had test coverage that a file URL with an explicit port is properly handled?Nope, I'm just confused about the bug we're fixing. ;)+1. It's a bigger diff, but it helps to convert this provider to our usual conventions and to give each case a unique key so it's easier to make sense of failures. I hope no one calls this "out of scope", since I think this is definitely worth keeping.
I was going to flag this as "weird, why use 80 as the port for the request, but 9000 for the file?", then I realized that's the bug we're fixing! ;)
The existing test is a little confusing, since
file_url_transform_relative()
itself is confusing. But the key point here is that these ports should *not* be the same.Maybe a comment to that effect, both in these test cases and with the fix? "Unique" didn't exactly clarify this for me, but maybe that's end-of-day brain talking. Something like "non-standard" or "different port than the web request" or something?
Comment #8
dwwInitial stab at a more accurate title for the issue. ;) Further refinements welcome!
Comment #9
quietone CreditAttribution: quietone as a volunteer commented@dww, thanks for the review.
Your comment is much better. Added it to file.inc and the array keys for the test. And I noticed that one of the tests should have been using 'https' so changed that.
Comment #10
dwwExcellent, much appreciated, @quietone! Everything now looks really good and clear.
Assuming the bot doesn't contradict me, RTBC. ;)
Thanks,
-Derek
Comment #15
larowlanCommitted b43c49e and pushed to 9.2.x. Thanks!
Backported to 9.1.x
Whilst the changes to the data-provider are borderline out of scope, I think they improve readability, assist debugging fails (named cases are much simpler to debug) and are a low risk of disruption.
Thanks all