Daily log - April 20, 2009
by Sean Cribbs
I made a method on my control that creates an array of regular expressions from the field input to match against our available data by splitting the field value on spaces. A piece of data will only match and be populated into the drop-down if all regexps match. Well, at first, I didn’t cover the edge case of having a piece of text with a space at the end and nothing following. When I tried to use the control in vivo, I got the “beachball” and then the “runaway script” warning. Naturally, it was because of this:
'an '.split(/\s+/) == ['an', '']
So the last element in the split array became a regexp that was essentially empty! Naturally it matched EVERYTHING and hung the browser.