Closed Bug 242325 Opened 20 years ago Closed 20 years ago

localHostOrDomainIs() never matches a hostname

Categories

(Core :: Networking, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: benc, Assigned: Stefan.Borggraefe)

References

()

Details

(Whiteboard: [good first bug] checkkwin, checklinux)

Attachments

(1 file)

From the PAC spec:

The following statement is true (host name match, domain name not specified):

localHostOrDomainIs("www", "www.netscape.com") 

However, I find that we never evaluate this case as true.

I've traced the problem in the localHostOrDomainIs() function to:

"        return (hostdom.search('/^' + host + '/') != -1);\n" +

For some reason, .search works if you hand it a literal, but not if you put a
variable or evaluate something in the ()

I've even gone into venkman to confirm this:

stuff="/www/"
"wwwblahblahblah".search(stuff)" = -1
but
"wwwblahblahblah".search(/www/) = 0
Neil was helpful in explaining what was wrong here, and has suggested logic that
is much more readable to me:

return host == hostdom || hostdom.lastIndexOf(host + '.', 0) == 0

This is very similar to what is currently used in dnsDomainIs().
OS: MacOS X → All
Hardware: Macintosh → All
Assignee: darin → Stefan.Borggraefe
Keywords: helpwanted
Whiteboard: [good first bug]
Adding URL of the relevant part of the spec.
Status: NEW → ASSIGNED
Comment on attachment 156108 [details] [diff] [review]
Neil's idea in the form of a patch

Darin, can you review this? Thanks! :-)
Attachment #156108 - Flags: review?(darin)
Comment on attachment 156108 [details] [diff] [review]
Neil's idea in the form of a patch

why lastIndexOf and not indexOf?

shouldn't localHostOrDomainIs("foo", "foo.foo.com") return true?
(In reply to comment #5)
> (From update of attachment 156108 [details] [diff] [review])
> why lastIndexOf and not indexOf?

indexOf always searches the whole string while lastIndexOf starts at the
beginning of the string and stops when the first character that doesn't match is
seen.

http://lxr.mozilla.org/mozilla/source/js/src/jsstr.c#987
http://lxr.mozilla.org/mozilla/source/js/src/jsstr.c#1051

Besides of this I think indexOf would work, too.

> shouldn't localHostOrDomainIs("foo", "foo.foo.com") return true?

Mhh, it does. "foo.foo.com".lastIndexOf("foo.", 0) returns 0.
Comment on attachment 156108 [details] [diff] [review]
Neil's idea in the form of a patch

OK, that makes sense to me now.  I misunderstood the meaning of the second
parameter.  I see that lastIndexOf(..., 0) is only ever going to do a single
string compare.

r=darin
Attachment #156108 - Flags: review?(darin) → review+
Attachment #156108 - Flags: superreview?(bzbarsky)
Comment on attachment 156108 [details] [diff] [review]
Neil's idea in the form of a patch

I'm not likely to get to this review in the next two weeks.
Attachment #156108 - Flags: superreview?(bzbarsky) → superreview?(brendan)
Attachment #156108 - Flags: superreview?(brendan) → superreview?(bzbarsky)
Comment on attachment 156108 [details] [diff] [review]
Neil's idea in the form of a patch

sr=bzbarsky
Attachment #156108 - Flags: superreview?(bzbarsky) → superreview+
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
V/fixed.
Using the test file:

file:///Users/benc/Public/mozilla-org/html/quality/networking/testing/PAC/byspecs/localHostOrDomainIs.pac

You can see in the js console that all the tests pass.
Status: RESOLVED → VERIFIED
Keywords: helpwanted
Whiteboard: [good first bug] → [good first bug] checkkwin, checklinux
whoops, references to my local cvs tree are useless...

here's the file:

//Test standards from spec.
function FindProxyForURL(url, host)
{


	if (localHostOrDomainIs("www.netscape.com", "www.netscape.com"))
		alert ("example #1 - PASS");
	if (localHostOrDomainIs("www", "www.netscape.com"))
		alert ("example #2 - PASS");
	if (!localHostOrDomainIs("www.mcom.com", "www.netscape.com"))
    		alert ("example #3 - PASS");
	if (!localHostOrDomainIs("home.netscape.com", "www.netscape.com"))
    		alert ("example #4 - PASS");
alert("done!");
}
Stefan: can you checkin for the 1.7 branch? (I'm out of date on what the rules
are..)
Attachment #156108 - Flags: approval1.7.6?
Comment on attachment 156108 [details] [diff] [review]
Neil's idea in the form of a patch

Too late for 1.7.6.  Also note that a fix to core needs to go into both 1.7 and
aviary branches.  If this fix is still wanted in the future, please make sure
to request approval for both branches.
Attachment #156108 - Flags: approval1.7.6? → approval1.7.6-
So wait until after 1.7.6 and get it into the branch?
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: