Problems with shipped files and Drupal 6 file_create_url() behavior
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #839282. -->
Reported by: [jcmarco](https://www.drupal.org/user/186555)
>>>
<p>I am working with last Pressflow 6 that includes the CDN patch with the new hook_file_url_alter, backported from the Drupal 7 file_create_url function.</p>
<p>I found a problem with the module taxonomy_image where it's using the file_create_url($path) having the $path a relative url from the files directory.<br>
By default it would be category_pictures as directory and as example it could be category_pictures/icon.png</p>
<p>Reading the original api function: <a href="http://api.drupal.org/api/function/file_create_url/6">http://api.drupal.org/api/function/file_create_url/6</a><br>
It seems that the use that taxonomy_image module is doing from that function it's correct.<br>
It passing a relative path for a file. And it would work fine with the old D6 function.</p>
<p>But the CDN patch is adding the shipped file feature from D7, and then when the function arrives to:</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br> </span><span style="color: #FF8000">// Shipped files.<br> </span><span style="color: #007700">if (</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">, </span><span style="color: #0000BB">file_directory_path</span><span style="color: #007700">() . </span><span style="color: #DD0000">'/'</span><span style="color: #007700">) !== </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br> return </span><span style="color: #0000BB">base_path</span><span style="color: #007700">() . </span><span style="color: #0000BB">$path</span><span style="color: #007700">;<br> }<br></span><span style="color: #0000BB">?></span></span></pre></div>
<p>It founds that $path=category_files/icon.png and file_directory_path = sites/all/default/files (for example) and then of course the $path doesn't include the file directory path and then it returns<br>
the base path and path returning /category_files/icon.png. That is wrong reading the api definition.</p>
<p>I open the issue here because I don't find any bug in the taxonomy_image function, but so, in the backporting of a D7 feature that alters the original D6 definition.</p>
<p>The shipped feature works fine if you are using files from the misc/, modules/, themes/ or sites/ directory when it just send the full url,<br>
but it fails for the case where you want to create a url from a relative path for a file that it is in your files directory, and you don't know if the files are private or public.</p>
<p>I know that the change in the taxonomy_images is tiny, but it could be affecting to more modules that are using the file_create_url function as it's defined in the api and thus this patch is breaking the D6 compatibility.</p>
<p>A possible solution could be checking for the shipped files that the url includes the misc/,modules/, sites/, themes/ (and possibly profiles/) paths, because on that case it wouldn't be a relative path for the files directory.</p>
issue