CodeSOD: In the Area (code)

This post was originally published on this site

The Daily WTF

Jeremy was sent hunting a bug in some older JavaScript code. The key problem was that many phone numbers were getting a US country code prepended to them, even when they already had a different country code and were in a different country than the US.

for(i in item.victims) { c = item.victims[i].country_code; n = item.victims[i].phone_number; if(n) { number = c ? c + ” + n : n if(number in Account.contacts) { number = Account.contacts[number]; } else { if(n.length == 10 || (n[0] == 1 && n.length > 10)) { s = n[0] == 1?1:0; number = ‘1 (‘ + n.substring(s, s+3) + ‘) ‘ + n.substring(s+3, s+6) + ‘-‘ + n.substring(s+6, s+10); } else { number = ‘+’ + c + ‘ ‘ + n; } } victims.push(number); } }

So this code examines each victim. We start by combining their phone number with their country code,

To read the full article click on the 'post' link at the top.