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:
asqueella@gmail.com 2007-04-27 07:50:15 -07:00
parent 8b13adb4c2
commit 2fca2dccd7
2 changed files with 20 additions and 3 deletions

View File

@ -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,

View 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);
}