Closed (duplicate)
Project:
Stage File Proxy
Version:
7.x-1.x-dev
Component:
Code
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Dec 2012 at 12:30 UTC
Updated:
24 Apr 2018 at 19:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
davidgrayston commentedAttached patch to prevent double slashes
Comment #2
davidgrayston commentedAttached patch with correct filename to prevent double slashes
Comment #3
gregglesIt does seem uncommon to put your files in / but that should be supported.
Should we document somewhere that an empty string is the right value to use instead of /? Needs work for that, otherwise RTBC from me.
Comment #4
davidgrayston commentedI think it would make sense to document an empty string as being the correct value. This falls inline with the current documentation that states the default value is 'sites/default/files', which has no leading or trailing slash.
It should already work with either '/' or '' as slashes get trimmed anyway.
Comment #5
gregglesAnother thought: what about just doing a preg_replace of // for / - then we can remove any documentation that mentions the need to keep or remove a trailing slash.
Comment #6
davidgrayston commentedIt should already work if you have leading and trailing slashes as they are removed with this line:
$remote_file_dir = trim(variable_get('stage_file_proxy_origin_dir', $file_dir),'/');
So '/sites/default/files/' becomes 'sites/default/files' and '/' becomes ''
The problem was arising because the $remote_dir_path was being concatenated between 2 slashes even when it was empty:
$url = $server . '/' . $remote_dir_path . '/' . rawurlencode($filename);
The patch is a minor tweak to this:
$url = $server . '/' . ($remote_dir_path != '' ? $remote_dir_path . '/' : '') . rawurlencode($filename);
The patch could be changed to preg_replace // for / whenever a URL is constructed like this:
$url = $server . preg_replace('|//|', '/', '/' . $remote_dir_path . '/' . rawurlencode($filename));
It's an alternative way of achieving the same result, which do you prefer?
Comment #7
gregglesAh, good point. Maybe we remove that trim and switch to the preg_replace solution a bit later in the code? That seems most likely to work and cleanest.
Comment #8
dave reid#2351485: Use hook_file_url_alter() to fetch files (fixes incompatibility with picture module) would also resolve this.
Comment #9
markdorisonIs this still a valid issue with #2351485: Use hook_file_url_alter() to fetch files (fixes incompatibility with picture module) committed?
Comment #10
gregglesBased on lack of response I'm closing this as a duplicate of #2351485: Use hook_file_url_alter() to fetch files (fixes incompatibility with picture module).