RegEx causes Browser to 'hang' and CF

View: New views
3 Messages — Rating Filter:   Alert me  

RegEx causes Browser to 'hang' and CF

by JediHomer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Ive got a system where we allow a user to upload a CSV containing
addressbook entries.  I run a RegEx Email validation to check that the
email of the record is in an appropriate format.  Currently I have the
following:

<cfset sPattern =
"([a-z0-9][-._a-z0-9]*)*[a-z0-9]+@{1,1}([a-z0-9][-_a-z0-9]*\.)+[a-z]{2,7}"
/>
return IIF(REFindNoCase(sFormatPattern, str) EQ 1, true, false);


And similarly in the Javascript:

var emailFilter =
/([a-zA-Z0-9][-._a-zA-Z0-9]*)*[a-zA-Z0-9]+@{1,1}([a-zA-Z0-9][-_a-zA-Z0-9]*\.)+[a-zA-Z]{2,7}/g;
return emailFilter.test(sEmail);


Using an email address of:

foobar.foobar.foobar.mediroute.snet.co.uk

causes the browser (for the javascript) to 'hang' using all the CPU
and causes CF to do similar (thus never rreturning the page to the
user)


Why is this happening, and how can I avoid potential problems like
this in the future.


Thanks in advance

Jedi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:21:878
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/21
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:21
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Parent Message unknown Re: RegEx causes Browser to 'hang' and CF

by S. Isaac Dealey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> <cfset sPattern =
> "([a-z0-9][-._a-z0-9]*)*[a-z0-9]+@{1,1}([a-z0-9][-_a-z0-9]
> *\.)+[a-z]{2,7}"
> />
> return IIF(REFindNoCase(sFormatPattern, str) EQ 1, true,
> false);


> And similarly in the Javascript:

> var emailFilter =
> /([a-zA-Z0-9][-._a-zA-Z0-9]*)*[a-zA-Z0-9]+@{1,1}([a-zA-Z0-
> 9][-_a-zA-Z0-9]*\.)+[a-zA-Z]{2,7}/g;
> return emailFilter.test(sEmail);

Not sure about the hanging, but for any reges that begins at the start
of the string and ends at the end of the string (like an email
address) I would think you should definately always have ^ at the
beginning and $ at the end of the expression.

Also I believe [a-zA-Z0-9] can be replaced with \w (or [[:alnum:]] in
CF if you want to use the widely un-used standard - I like the posix
character classes because they're a good semantic, i.e. they're
descriptive unlike any of the other syntaxes)...

You can also make your javascript regex case insensitive by adding "i"
on the end... you don't need the "g" because you're not replacing
anything... so... /expression/i should help you out there...

You've got an extra * in there... where your expressions both have
]*)* ... drop the * after the ) should just be ]*) -- that might have
something to do with the hanging issue -- I wouldn't have expected as
such, but it's possible...

You've also got a {1,1} you don't need... {1,1} is the default for any
character, so @{1,1} is the same as @

The parenthesis in general look unnecessary... Are you using those for
replacement later in the script? If not, then remove the parenthesis
all-together...

hth



s. isaac dealey     954.522.6080
new epoch : isn't it time for a change?

add features without fixtures with
the onTap open source framework

http://www.fusiontap.com
http://coldfusion.sys-con.com/author/4806Dealey.htm


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting.
http://www.houseoffusion.com/banners/view.cfm?bannerid=11

Message: http://www.houseoffusion.com/lists.cfm/link=i:21:879
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/21
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:21
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Re: RegEx causes Browser to 'hang' and CF

by Ben Doom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Floading in the archives here, there's a reccommended regex for email.
I suspect that the way you've written yours is causing the engine to
have to backtrack too many times.  But that's just a guess.

--Ben

JediHomer wrote:

> Hi,
>
> Ive got a system where we allow a user to upload a CSV containing
> addressbook entries.  I run a RegEx Email validation to check that the
> email of the record is in an appropriate format.  Currently I have the
> following:
>
> <cfset sPattern =
> "([a-z0-9][-._a-z0-9]*)*[a-z0-9]+@{1,1}([a-z0-9][-_a-z0-9]*\.)+[a-z]{2,7}"
> />
> return IIF(REFindNoCase(sFormatPattern, str) EQ 1, true, false);
>
>
> And similarly in the Javascript:
>
> var emailFilter =
> /([a-zA-Z0-9][-._a-zA-Z0-9]*)*[a-zA-Z0-9]+@{1,1}([a-zA-Z0-9][-_a-zA-Z0-9]*\.)+[a-zA-Z]{2,7}/g;
> return emailFilter.test(sEmail);
>
>
> Using an email address of:
>
> foobar.foobar.foobar.mediroute.snet.co.uk
>
> causes the browser (for the javascript) to 'hang' using all the CPU
> and causes CF to do similar (thus never rreturning the page to the
> user)
>
>
> Why is this happening, and how can I avoid potential problems like
> this in the future.
>
>
> Thanks in advance
>
> Jedi
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:21:880
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/21
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:21
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54