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.