Issue Details (XML | Word | Printable)

Key: MDL-16272
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jerome Mouneyrac
Reporter: Jeff Therrien
Votes: 0
Watchers: 0
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Link to File with Anchor (blank.html#anchor) Gives "Sorry, the requested file could not be found" Error

Created: 29/Aug/08 11:01 PM   Updated: 17/Feb/09 11:27 AM
Component/s: Resource
Affects Version/s: 1.9.2
Fix Version/s: 1.9.5

File Attachments: 1. Text File MDL-16272.patch (0.8 kB)

Environment: Linux/Apache/PHP4/MySQL

Participants: Eloy Lafuente (stronk7), Jeff Therrien, Jerome Mouneyrac and Tim Hunt
Security Level: None
QA Assignee: Tim Hunt
Resolved date: 05/Feb/09
Affected Branches: MOODLE_19_STABLE
Fixed Branches: MOODLE_19_STABLE


 Description  « Hide
Upload an HTML file to a course. Now, add a resource linking to that uploaded file and include an anchor as part of the link (ex. blah.html#anchor). When you follow the resource link, you should receive the error "Sorry, the requested file could not be found".

This problem does not occur when linking to external files.

It looks like the URL to the file is in the form http://server.com/file.php/xx/index.html%23anchor instead of http://server.com/file.php/xx/index.html#anchor where # is being changed to %23.



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Eloy Lafuente (stronk7) added a comment - 01/Sep/08 03:35 PM
I guess we are urlencoding too much.

Jerome can you reproduce and if possible, avoid urlscaping colons, slashes and hashes? : / #

And see if that fixes the problem. Ciao


Jerome Mouneyrac added a comment - 10/Sep/08 04:01 PM
Hi,
first look: I confirmed the bug and that the url gets rawurlencode()
it's here:

------------------------------------------------------------
mod/resource/type/file/resource.class.php
------------------------------------------------------------
316: $fullurl = get_file_url($course->id.'/'.$resource->reference, $querys);

------------------------------------------------------------
filelib.php
------------------------------------------------------------
5 : function get_file_url(...){ 35 : $parts = array_map('rawurlencode', $parts); //we should not encode the anchor hash 51 : }


Jerome Mouneyrac added a comment - 07/Jan/09 04:18 PM - edited
Here a solution for managing anchor:
------------------------------------------
Current code
------------------------------------------
if ($CFG->slasharguments) { $parts = explode('/', $path); $parts = array_map('rawurlencode', $parts); $path = implode('/', $parts); $ffurl = $url.'/'.$path; $separator = '?'; }
------------------------------------------
Patch
------------------------------------------
if ($CFG->slasharguments) {
$parts = explode('/', $path);
foreach ($parts as $key => $part) { $subparts = explode('#', $part); $subparts = array_map('rawurlencode', $subparts); $parts[$key] = implode('#', $subparts); }
$path = implode('/', $parts);
$ffurl = $url.'/'.$path;
$separator = '?';
}

Looking if we really need to manage colon (it would complicate the code for nothing)


Jerome Mouneyrac added a comment - 15/Jan/09 11:34 AM - edited
This patch needs to be reviewed before commit. (open an new issue for colon if needed)

Eloy Lafuente (stronk7) added a comment - 04/Feb/09 09:57 AM
Tested here with $path string seems to work perfectly with hashes and slashes being respected. So, I think we can ignore colons for now.

Note: In HEAD, I've found TWO occurrences of "array_map('rawurlencode"), one in lib/filelib and another in lib/file/file_browser.php. Not sure if both need the hash-hack but ideally it should be present IMO.

+1 Thanks!


Jerome Mouneyrac added a comment - 05/Feb/09 11:26 AM
Thanks Jeff for the report.
Thanks Eloy for the review.
commited

Tim Hunt added a comment - 17/Feb/09 11:27 AM
Tested and reviewed code. It works. Thanks.