text match tip - do not default strategy if text may incl. a colon

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

text match tip - do not default strategy if text may incl. a colon

I just had a "forehead-flattening" moment while working on some Selenium tests.

Originally, I had a test like this:


as it happens, values my application may produce for the variable 'siteName' can include one or more colon characters. Assume for example, that 'siteName' had a value on one test run  of 'abcdef:ghijk::lmnop'.

Upon running the test, I got an error "cannot find PatternMatcher.strategies.abcdef"

Ultimately, I ended up checking htmlutils.js and realized that the way it's written, a colon in the matched text will make it think that everything before the colon is supposed to be a strategy, which of course is wrong - there are only 'regexp', 'exact' and 'glob'. 'glob' is the assumed default. Any other non-null string throws the error I got.

After getting myself all wound up and ready to revise how the PatternMatcher.prototype is written, I realized all I had to do was to explicitly use one of the strategies, and everything would be fine. (open hand smacks forehead)

So, I simply revised my test to be like this:


and all was well. I could have used one of the other choices in my case, but the key point here is that if you think the value you're matching against may include a colon, then you need to be explicit about one of the matching strategies in your test.

Hope this helps somebody else avoid this little trap (then I won't feel like such a knuckle-head for having fallen into it myself ;-) )

Posted via Jive Forums

To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]