mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 368702 - Effective TLD Service should treat trailing dot properlyp=Wladimir Palant <trev.moz@adblockplus.org>r=biesi, sr=dveditz
This commit is contained in:
parent
8b13adb4c2
commit
2fca2dccd7
@ -219,10 +219,12 @@ nsEffectiveTLDService::GetEffectiveTLDLength(const nsACString &aHostname,
|
||||
PRUint32 *effTLDLength)
|
||||
{
|
||||
// Calcluate a default length: either the level-0 TLD, or the whole string
|
||||
// length if no dots are present.
|
||||
// length if no dots are present. Make sure to ignore the trailing dot if one
|
||||
// is there.
|
||||
PRInt32 nameLength = aHostname.Length();
|
||||
PRInt32 trailingDotOffset = (nameLength && aHostname.Last() == '.' ? 1 : 0);
|
||||
PRInt32 defaultTLDLength;
|
||||
PRInt32 dotLoc = FindEarlierDot(aHostname, nameLength - 1);
|
||||
PRInt32 dotLoc = FindEarlierDot(aHostname, nameLength - 1 - trailingDotOffset);
|
||||
if (dotLoc < 0) {
|
||||
defaultTLDLength = nameLength;
|
||||
}
|
||||
@ -240,7 +242,7 @@ nsEffectiveTLDService::GetEffectiveTLDLength(const nsACString &aHostname,
|
||||
|
||||
// Walk the domain tree looking for matches at each level.
|
||||
SubdomainNode *node = &sSubdomainTreeHead;
|
||||
dotLoc = nameLength;
|
||||
dotLoc = nameLength - trailingDotOffset;
|
||||
while (dotLoc > 0) {
|
||||
PRInt32 nextDotLoc = FindEarlierDot(normHostname, dotLoc - 1);
|
||||
const nsCSubstring &subname = Substring(normHostname, nextDotLoc + 1,
|
||||
|
15
netwerk/test/unit/test_bug368702.js
Normal file
15
netwerk/test/unit/test_bug368702.js
Normal file
@ -0,0 +1,15 @@
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
function run_test() {
|
||||
var tld =
|
||||
Cc["@mozilla.org/network/effective-tld-service;1"].
|
||||
getService(Ci.nsIEffectiveTLDService);
|
||||
|
||||
do_check_eq(tld.getEffectiveTLDLength("localhost"), 9);
|
||||
do_check_eq(tld.getEffectiveTLDLength("localhost."), 10);
|
||||
do_check_eq(tld.getEffectiveTLDLength("domain.com"), 3);
|
||||
do_check_eq(tld.getEffectiveTLDLength("domain.com."), 4);
|
||||
do_check_eq(tld.getEffectiveTLDLength("domain.co.uk"), 5);
|
||||
do_check_eq(tld.getEffectiveTLDLength("domain.co.uk."), 6);
|
||||
}
|
Loading…
Reference in New Issue
Block a user