Article 6G475 CodeSOD: Not My Domain

CodeSOD: Not My Domain

by
Remy Porter
from The Daily WTF on (#6G475)

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.

buildmaster-icon.png [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments