Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Validation of user provided regex

Reply
Thread Tools

Validation of user provided regex

 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-12-2007
In an app where a user may provide a Perl regular expression I want to
validate the regex before it's applied. Currently I'm doing something like:

{
local $SIG{__WARN__} = sub { die $_[0] };
eval { $regex = qr($regex) };
die $@ if $@;
}

In other words I rely on Perl's ability to catch errors, where also
warnings are treated as errors.

Are there other appropriate checks that could be done?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      07-12-2007
Gunnar Hjalmarsson <> wrote in comp.lang.perl.misc:
> In an app where a user may provide a Perl regular expression I want to
> validate the regex before it's applied. Currently I'm doing something like:
>
> {
> local $SIG{__WARN__} = sub { die $_[0] };
> eval { $regex = qr($regex) };
> die $@ if $@;
> }
>
> In other words I rely on Perl's ability to catch errors, where also
> warnings are treated as errors.
>
> Are there other appropriate checks that could be done?


If code interpolations are a possibility, you may want to "use re
'eval';" in the block. Or not, depending...

Anno
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-13-2007
wrote:
> Gunnar Hjalmarsson <> wrote in comp.lang.perl.misc:
>> In an app where a user may provide a Perl regular expression I want to
>> validate the regex before it's applied. Currently I'm doing something like:
>>
>> {
>> local $SIG{__WARN__} = sub { die $_[0] };
>> eval { $regex = qr($regex) };
>> die $@ if $@;
>> }
>>
>> In other words I rely on Perl's ability to catch errors, where also
>> warnings are treated as errors.
>>
>> Are there other appropriate checks that could be done?

>
> If code interpolations are a possibility, you may want to "use re
> 'eval';" in the block. Or not, depending...


Thanks for the tip, but I really don't see a need for using (?{ ... }),
so I guess I'd better not.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rationale behind user provided ctor requirement for const objectsof non-POD class types Nikos Chantziaras C++ 6 05-25-2011 12:37 AM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
User Provided CSS Adi ASP .Net 2 09-21-2007 07:36 AM
Computer Support Forums : Provided By User: DlSoftware DlSoftware Computer Support 44 04-19-2007 05:52 PM
Re: DOT NET frame work provided session management using SQL SERVER MS News \(MS ILM\) ASP .Net 0 08-26-2003 12:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57