Last modified: 2011-05-06 06:50:04 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T30627, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 28627 - wfMakeUrlIndex throws "Undefined index: host" for file links with more than two slashes
wfMakeUrlIndex throws "Undefined index: host" for file links with more than t...
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.18.x
All All
: Low normal (vote)
: ---
Assigned To: Brion Vibber
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-04-20 19:26 UTC by Dan Barrett
Modified: 2011-05-06 06:50 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Dan Barrett 2011-04-20 19:26:58 UTC
The function wfMakeUrlIndex() in includes/GlobalFunctions.php throws an error if passed a file URI that has more than two slashes after "file://".

PHP Notice:  Undefined index: host in <path>/w/includes/GlobalFunctions.php on line 2636

This is because PHP's parse_url() function handles file URIs differently depending on the number of slashes after "file:". If you have two slashes, you get a 'host' array element:

print_r(parse_url('file:///whatever/you/like.txt'));

Array
(
    [scheme] => file
    [host] => whatever
    [path] => /you/like.txt
)

but with three or more slashes, you don't:

print_r(parse_url('file:///whatever/you/like.txt'));

Array
(
    [scheme] => file
    [path] => /whatever/you/like.txt
)

This screws up all references to $bits['host'] in wfMakeUrlIndex.

I believe wfMakeUrlIndex() should handle file URIs specially, just as it does "mailto" URIs today. It should accept ANY number of slashes after "file:", because both IE and Firefox today accept these URIs (e.g., representing Windows network shares).
Comment 1 Dan Barrett 2011-04-20 19:27:44 UTC
This code is old. It definitely behaves this way in MediaWiki 1.16.4, and the code looks unchanged in 1.18-svn, so I filed it as 1.18-svn.
Comment 2 Dan Barrett 2011-04-20 19:29:03 UTC
Argh, I have typos in my code examples. (Wish I could edit them!) The first example, where you have two slashes, should read:

If you have two slashes, you get a 'host' array element:

print_r(parse_url('file://whatever/you/like.txt'));

Array
(
    [scheme] => file
    [host] => whatever
    [path] => /you/like.txt
)
Comment 3 Dan Barrett 2011-04-20 19:44:06 UTC
Alternatively, you should just check for the existence of $bits['host'] before referencing it, and take some corrective action, eliminating the PHP Notice message.
Comment 4 Mark A. Hershberger 2011-04-20 19:51:54 UTC
patches welcome.
Comment 5 Dan Barrett 2011-04-20 21:24:29 UTC
I would be happy to patch, but I am missing some domain knowledge.

In the externallinks table, what should the el_index column contain for a file:// URI? The current code produces a weird-looking result. For the file link:

file:///mywindowsshare.net/foo/bar/blat.xls 

it creates an el_index value of:

file://./mywindowsshare.net/foo/bar/blat.xls

I have no clue if this is right or wrong....
Comment 6 Bawolff (Brian Wolff) 2011-04-20 21:56:13 UTC
If i recall:

file:///foo/bar.txt (3 slashes) means the file foo/bar.txt on the current host, where 2 slashes - file://whatever/foo.txt means the file foo.txt on the host named whatever. So php's behaviour is kind of right... However our behaviour is definitely still wrong
Comment 7 Dan Barrett 2011-04-22 15:04:00 UTC
Reiterating something above:

If you fix this, be sure not to limit yourself to 3 slashes. File URI's with many slashes, such as file://///myshare/foo/bar.txt, should be considered correct too. The major browsers accept them, and in fact, sometimes require them in odd cases.
Comment 8 Brion Vibber 2011-04-25 21:04:34 UTC
Committed fix to trunk in r86897. Includes some test cases in the GlobalTest chunk of the phpunit tests.

Change checks if 'host' is present and slips in just '.' if not. (Or should we use localhost? Technically not the same... sorta. :)

This handles file:///path/foo, file:///c:/path/foo, and file://server/path/foo reasonably well.

Multi-slash cases (file://///share/foo) aren't normalized to match the expected more canonical forms (file://share/foo) but they'll go through without error. The lack of consistency between browsers and OSs, and many browsers keeping file: urls disabled for HTTP pages, means we probably can expect folks to be using the IE/Windows style for most actual cases of intranet use.
Comment 9 p858snake 2011-05-06 06:50:04 UTC
*Bulk BZ change: -bugsmash from closed bugs. (7 Bugs)*

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links