Not My Domain – The Daily WTF – The TechLead

[ad_1]

Dian found this code snippet.

String[] key_value = url.split("\.");

for (int i=key_value.length; i>0; i--) 
        if (i > 1)
                domain = key_value[i-2]+"."+key_value[i-1];
        break;

“I’m still not sure what this is supposed to do,” Dian writes.

I believe this is someone’s attempt to extract the TLD and primary domain from a URL, e.g. www.mysite.com becomes mysite.com. (Remember when wwws were on every domain name?) Why they chose to use a loop that only executes once, I’ll never understand.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *