Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > pattern match of possibly "dangerous" strings

Reply
Thread Tools

pattern match of possibly "dangerous" strings

 
 
alexxx.magni@gmail.com
Guest
Posts: n/a
 
      06-28-2007
Hi all,
I have a small program that crawls my filesystem, checking filenames
and doing useful stuff.
The heart of it, of course is a pattern match line, where the filename
under check is compared to a pattern.
Everything was running perfectly until I got:

/0ale/excursions/digital/manuals/O'Reilly Perl CD Bookshelf v2.0/
advprog/examples/Extending/Typemaps_with_XS/00comment.txt exists,
updating it

Nested quantifiers in regex; marked by <-- HERE in m/^\s+Car_c++ <--
HERE _obj ! (\S.*)/ at /0ale/excursions/digital/script/comment-dev
line 271.


(1st line is my prog. output, 2nd line is the error)
apart from the fun fact that the error came while crawling the Perl
Bookshelf, I immediately noticed that names containing special chars
(as that damn directory Car_c++_obj) can bring trouble.
How can I be sure that a generic string read in $_ can be safely put
in a RE, without its chars being misunderstood as RE special chars???

Thanks!

Alessandro Magni

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      06-28-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have a small program that crawls my filesystem, checking filenames
> and doing useful stuff.
> The heart of it, of course is a pattern match line, where the filename
> under check is compared to a pattern.
> Everything was running perfectly until I got:
>
> /0ale/excursions/digital/manuals/O'Reilly Perl CD Bookshelf v2.0/
> advprog/examples/Extending/Typemaps_with_XS/00comment.txt exists,
> updating it
>
> Nested quantifiers in regex; marked by <-- HERE in m/^\s+Car_c++ <--
> HERE _obj ! (\S.*)/ at /0ale/excursions/digital/script/comment-dev
> line 271.
>
>
> (1st line is my prog. output, 2nd line is the error)
> apart from the fun fact that the error came while crawling the Perl
> Bookshelf, I immediately noticed that names containing special chars
> (as that damn directory Car_c++_obj) can bring trouble.
> How can I be sure that a generic string read in $_ can be safely put
> in a RE, without its chars being misunderstood as RE special chars???


perldoc -f quotemeta

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
alexxx.magni@gmail.com
Guest
Posts: n/a
 
      06-28-2007
thank you,
I didnt know about this particular kind of quote - it sertainly works
now with a simple $q=quotemeta($_);

Alessandro

On Jun 28, 5:06 pm, Gunnar Hjalmarsson <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > I have a small program that crawls my filesystem, checking filenames
> > and doing useful stuff.
> > The heart of it, of course is a pattern match line, where the filename
> > under check is compared to a pattern.
> > Everything was running perfectly until I got:

>
> > /0ale/excursions/digital/manuals/O'Reilly Perl CD Bookshelf v2.0/
> > advprog/examples/Extending/Typemaps_with_XS/00comment.txt exists,
> > updating it

>
> > Nested quantifiers in regex; marked by <-- HERE in m/^\s+Car_c++ <--
> > HERE _obj ! (\S.*)/ at /0ale/excursions/digital/script/comment-dev
> > line 271.

>
> > (1st line is my prog. output, 2nd line is the error)
> > apart from the fun fact that the error came while crawling the Perl
> > Bookshelf, I immediately noticed that names containing special chars
> > (as that damn directory Car_c++_obj) can bring trouble.
> > How can I be sure that a generic string read in $_ can be safely put
> > in a RE, without its chars being misunderstood as RE special chars???

>
> perldoc -f quotemeta
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl



 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      06-28-2007
On Jun 28, 11:37 am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> On Jun 28, 5:06 pm, Gunnar Hjalmarsson <(E-Mail Removed)> wrote:
> > perldoc -f quotemeta


> I didnt know about this particular kind of quote - it
> sertainly works now with a simple $q=quotemeta($_);


Read the doc Gunnar pointed you to again. It's simpler than that.
Just use the \Q (and possibly \E) characters within your regexp.

perldoc perlre

Paul Lalli

 
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
How to replace all strings matching a pattern with correspondinglower case strings ? anonym Java 1 01-15-2009 07:29 PM
A story sort of solved- the image ...dll is possibly corrupt. Theheader checksum does not match jameshanley39@yahoo.co.uk Computer Information 12 04-02-2008 08:05 AM
convert structured strings to possibly deep hash of hashes seven.reeds Perl Misc 9 08-10-2006 03:15 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM



Advertisments