Closed Bug 290782 Opened 20 years ago Closed 19 years ago

URIs passed to firefox lacking http:// fails

Categories

(Toolkit :: Startup and Profile System, defect, P2)

x86
Windows XP
defect

Tracking

()

RESOLVED FIXED
mozilla1.8beta4

People

(Reporter: tom, Assigned: benjamin)

References

()

Details

(Keywords: regression, Whiteboard: has patch with review, needs approval)

Attachments

(2 files, 2 obsolete files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2) Gecko/20050417 Firefox/1.0+
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2) Gecko/20050417 Firefox/1.0+

in mIRC, clicking urls lacking a http:// fails.  in other programs (tested in
MSN 7) it doesn't.

tests:
* open "www.google.com" in run menu, success
* open "http://www.google.com" in run menu, success
* open "firefox www.google.com" in run menu, failure, result:
The file /C:/Documents and Settings/Tom/www.google.com cannot be found. Please
check the location and try again.

This is because urls passed to firefox directly (as mIRC does, because it used
to always pass them to IE directly and there was some registry hack to fix that,
now it's fixed in 6.16 and passes directly to the default browser instead of to
windows which would then pass it properly) which lack an http:// fail.


Reproducible: Always

Steps to Reproduce:
1. Open Start > Run
2. type "firefox www.google.com"
3. Get error message/page

Actual Results:  
shows error

Expected Results:  
append http:// and go to google

Thanks for the help of jesus_X and sp3k while filing this bug.

Thanks to Wolf for catching that this is a regression caused by bug 276588.
Assignee: firefox → nobody
Component: General → XRE Startup
Keywords: regression
Product: Firefox → Toolkit
QA Contact: general → nobody
Summary: [REGRESSION] URIs passed to firefox lacking http:// fails → URIs passed to firefox lacking http:// fails
Assignee: nobody → benjamin
* If mIRC makes the judgement in its domain of expertise, irc content, that
www.google.com should be presented as a http link, but then passes it on to a
handler bare without specifying the http bit, relying on the handler to make the
same guess about its nature without the context that mIRC had to make that
guess, that's a bug in mIRC and should be fixed, regardless of what firefox does.

* I hear that Start -> Run |iexplore www.google.com| goes to google, so IE
parity would be to do the same.

* I'd prefer |firefox nonexistentfile| on the command line to act predictably
and fail, rather than go play with DNS, to be consistent with the common pattern
of non-option arguments being file names.
I just thought this thought provoking line would be useful to all parties:

[01:17:21] <Jesse> i saw code in mozilla that was supposed to notice that
there's no file called www.X.com and treat it as a URL instead of a filename
Status: UNCONFIRMED → NEW
Ever confirmed: true
Blocks: 277865
non-option arguments to firefox are treated as URLs relative to the current
working directory. So we actually try to load
file:///C:/Current/Directory/www.google.com which of course doesn't exist.
I think firefox 1.1 will be blamed for breaking links like "www.foo.com" from
other applications.  This will be a pain point as we may not have the luxury to
expect other applications to be fixed.
Severity: minor → normal
Flags: blocking-aviary1.1?
Flags: blocking1.8b4?
we'll evaluate for 1.8b4. if it doesn't make that train, it doesn't make 1.1.
Flags: blocking-aviary1.1?
bsmedberg:

How about we try treating the argument as a relative file URL, and if that does
not identify a file, then we try loading it by slapping http:// in front of it?
Does that sound reasonable?
Well, "~/www.mozilla.org" does identify a file, it's just that the file doesn't
exist. Remember that this API isn't just for firefox, when composer uses it you
might be able to expect

./nvu myfile.html (which doesn't exist) to continue to work. So a simple
nsIFile.exists check won't work.

So I expect we need a smarter mechanism that looks for common
prefixes/suffixes/multiple dots/something. Although I didn't expect this
particular problem, this is one of the reasons I made the
nsICommandLine.resolveURI function, to encapsulate any interesting 
Is there no way for the browser to inject a command line handler that would
inspect the relative URI and determine that it should be handled as a http://
instead of as a relative file URI?
That is possible, we could just put a helper function in nsBrowserContentHandler
that does multi-part resolution.
Whatever heuristic gets used doesn't have to be very clever, because the main
source of the issue is programs like mIRC that pass in links that they
themselves have heuristically detected. As far as I can tell the only
protocol-less links that mIRC detects are those starting with "www." or "ftp.",
for example.

Bizarrely enough, IE seems to consider _anything_ without a path to be a
hostname; try running "iexplore example.com", "iexplore example.tld", "iexplore
example" or even the name of a filename that exists in the current working
directory. It probably relies on Windows Explorer associations always passing it
a fully qualified path for local files. So basically anything Firefox implements
would be smarter than what IE does.
Flags: blocking1.8b4? → blocking1.8b4+
Priority: -- → P2
Target Milestone: --- → mozilla1.8beta3
Flash 8 beta installer, after it finishes installing, sends me back here.  It
forgot to pass the http:// as well, I guess.  Not terribly sure why, though.

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b3) Gecko/20050715
Firefox/1.0+
*** Bug 267435 has been marked as a duplicate of this bug. ***
Attachment #189804 - Flags: first-review?(darin)
I think it would be more sane, and possibly more secure, to require a
command-line flag (such as -file) before local filenames.  I don't like the way
a typo in a filename could take you to a website when you're trying to open a
local file, and a stray local file could take you to a local file when you're
trying to open a website.
jesse: that is a good idea.  we should similarly have a -url command line flag.
 then, we'd want to make sure that -url is used when ShellExecute is called by
some other application.
Jesse, I consider this entirely a backwards-compatibility hack for xchat and
others who are bogusly calling "www.mozilla.org" intead of
"http://www.mozilla.org". There are lots of old behaviors that we have to
continue to support.
I'm not familiar with the Mozilla APIs, but it looks like that code would stick
http:// onto URIs that start with ftp, which is probably not what we want.
Comment on attachment 189804 [details] [diff] [review]
Use heuristics if the file doesn't exist, rev. 1

>Index: browser/components/nsBrowserContentHandler.js

>+  if (! uri instanceof nsIFileURL) {
>+    return uri;
>+  }
>+
>+  try {
>+    if (uri.QuerInterface(nsIFileURL).file.exists())
>+      return uri;

If "instanceof" returned true, then |uri| is already QI'd to
nsIFileURL for you.  There is no need to QI again.


>+  if (aArgument.match(/^(www|ftp)\.([a-z0-9]+\.)+[a-z]{2,5}(\/|$)/)) {
>+    var io = Components.classes["@mozilla.org/network/io-service;1"]
>+                       .getService(nsIIOService);
>+
>+    try {
>+      uri = io.newURI("http://" + aArgument, null, null);
>+    }

For "ftp." wouldn't you want to prepend "ftp://" instead of "http://"?
Have you considered using the URL bars fixup code?  see nsIURIFixup.
Attachment #189804 - Flags: first-review?(darin) → first-review-
It turns out the instanceof thing was due to the "!" operator binding more
tightly than "instanceof", so it was doing "false instanceof nsIFileURL".
Attachment #189804 - Attachment is obsolete: true
Attachment #190419 - Flags: first-review?(darin)
Whiteboard: has patch, needs review darin
Target Milestone: mozilla1.8beta3 → mozilla1.8beta4
Comment on attachment 190419 [details] [diff] [review]
Use heuristics if the file doesn't exist, rev. 1.1

>Index: browser/components/nsBrowserContentHandler.js

>+  // We have interpreted the argument as a relative file URI, but the file
>+  // doesn't exist. Try URI fixup heuristics: see bug 290782.
>+
>+  if (aArgument.match(/^(www|ftp)\.([a-z0-9]+\.)+[a-z]{2,5}(\/|$)/)) {
>+    var urifixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
>+                             .getService(nsIURIFixup);
>+
>+    try {
>+      uri = urifixup.createFixupURI(aArgument, 0);
>+    }
>+    catch (e) {
>+      Components.utils.reportError(e);
>+    }
>+  }

I don't understand.  Why does the string have to start with ftp.
or www. in order to go through URI fixup land?	I'd just pass it
to createFixupURI we couldn't get a file URL from it.  What's the
harm of doing that?  With the current code, we have URI fixup
rules in two places, and that doesn't seem so good.
Attachment #190419 - Flags: first-review?(darin) → first-review-
Do you want to pass "index.html" through uri-fixup? I don't think it will give
us what we're looking for, though if the file doesn't exist I'm not sure it matters.
Exactly.  I'm concerned with "cnn" and such.  Basically, URLFixup is what we do
to correct things entered into the URL bar, and I would think that we should
treat the command line like the URL bar (with the exception of trying to match
relative file paths first).  I see that you are disallowing keyword lookup and
the alternate URI feature... hmm...
*** Bug 302591 has been marked as a duplicate of this bug. ***
OK, I'm not sure I like this: if I use urifixup unconditionally with a missing
"index.html", urifixup succeeds with the URI "http://www.index.html".
Well, FF 1.0 invoked with a non-existent "index.html" tries to look up
"www.index.html" so we've been doing that for some time already....
bsmedberg: i'm just arguing for consistency between the command line and the url
bar.  maybe that's not desirable?
ok, I'll capitulate ;-)... it's no worse and quite a bit better than 1.0 was.
Attachment #190419 - Attachment is obsolete: true
Attachment #191396 - Flags: first-review?(darin)
Attachment #191396 - Flags: first-review?(darin) → first-review+
Attachment #191396 - Flags: approval1.8b4?
Whiteboard: has patch, needs review darin → has patch with review, needs approval
Comment on attachment 191396 [details] [diff] [review]
Use heuristics if the file doesn't exist, rev. 1.2

a=chase@mozilla.org
Attachment #191396 - Flags: approval1.8b4? → approval1.8b4+
Fixed on trunk for 1.8b4
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
*** Bug 304401 has been marked as a duplicate of this bug. ***
Component: XRE Startup → Startup and Profile System
QA Contact: nobody → startup
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: