Tuesday, July 21, 2015

ColdFusion email validation regex timeout

Once upon a time, before ColdFusion 9 introduced isvalid(), I made my own function using regex I found online for validating emails.
([A-Za-z0-9]|.|_|\-)+@([A-Za-z0-9]|_|\-)+[.]{1}([A-Za-z]|.|_|\-)+
Validation worked fine. Sometimes the form was slow, for seemingly no reason with there being no queries or anything which would slow things down. As it was occasional and seemingly unreplicatable, I ignored it.
Yesterday, a particular form, which was prepopped with a new member's email, stopped working. After submit, and a few minutes waiting, there was a timeout error with error pointing at cfmail. Commenting out cfmail just moved the line reported to a cfoutput tag. After some collaborative troubleshooting, we figured out that the issue was the long email.
I replace my custom function with isvalid(), which fixed the problem. However, the timeout still made no sense, so I took a close look at the regex I was using. The issue was that the + was outside the parenthesis, instead of inside. The longer the email, the longer ColdFusion would spend capturing all the possible matches. Adding ?: did not help. Moving the + inside, did. This is the correct regex to use if not using isvalid().
([A-Za-z0-9\._\-]+)@([A-Za-z0-9_\-]+)[.]{1}([A-Za-z\._\-]+)

Sunday, July 12, 2015

An unintentional missile

"The others found their chairs and slid neatly into them. Except - inevitably - for Carson Clinkscales, who managed to trip over what appeared to be his own feet. The ensign fell to his right, and his left arm, windmilling for balance, took Lieutenant Commander McGinley's GSN cap off her head. The heavy peaked cap catapulted across the conference table, hit the polished surface, slid past Andreas Venizelos' reaching hand with demonic precision, and struck a carafe of ice water dead center. The unintentional missile had just enough kinetic energy to knock the carefe over, and water exploded from it as the top some steward had neglected to fasten properly popped clear. Three different people clutched for the carafe, bot none reached it, and Captain Greentree gasped as the container rolled off the table and an ice-cold fountain inundated his lap."
Weber, D. In Enemy Hands 169.