| 1 | package re;
|
|---|
| 2 |
|
|---|
| 3 | our $VERSION = 0.05;
|
|---|
| 4 |
|
|---|
| 5 | =head1 NAME
|
|---|
| 6 |
|
|---|
| 7 | re - Perl pragma to alter regular expression behaviour
|
|---|
| 8 |
|
|---|
| 9 | =head1 SYNOPSIS
|
|---|
| 10 |
|
|---|
| 11 | use re 'taint';
|
|---|
| 12 | ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here
|
|---|
| 13 |
|
|---|
| 14 | $pat = '(?{ $foo = 1 })';
|
|---|
| 15 | use re 'eval';
|
|---|
| 16 | /foo${pat}bar/; # won't fail (when not under -T switch)
|
|---|
| 17 |
|
|---|
| 18 | {
|
|---|
| 19 | no re 'taint'; # the default
|
|---|
| 20 | ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
|
|---|
| 21 |
|
|---|
| 22 | no re 'eval'; # the default
|
|---|
| 23 | /foo${pat}bar/; # disallowed (with or without -T switch)
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | use re 'debug'; # NOT lexically scoped (as others are)
|
|---|
| 27 | /^(.*)$/s; # output debugging info during
|
|---|
| 28 | # compile and run time
|
|---|
| 29 |
|
|---|
| 30 | use re 'debugcolor'; # same as 'debug', but with colored output
|
|---|
| 31 | ...
|
|---|
| 32 |
|
|---|
| 33 | (We use $^X in these examples because it's tainted by default.)
|
|---|
| 34 |
|
|---|
| 35 | =head1 DESCRIPTION
|
|---|
| 36 |
|
|---|
| 37 | When C<use re 'taint'> is in effect, and a tainted string is the target
|
|---|
| 38 | of a regex, the regex memories (or values returned by the m// operator
|
|---|
| 39 | in list context) are tainted. This feature is useful when regex operations
|
|---|
| 40 | on tainted data aren't meant to extract safe substrings, but to perform
|
|---|
| 41 | other transformations.
|
|---|
| 42 |
|
|---|
| 43 | When C<use re 'eval'> is in effect, a regex is allowed to contain
|
|---|
| 44 | C<(?{ ... })> zero-width assertions even if regular expression contains
|
|---|
| 45 | variable interpolation. That is normally disallowed, since it is a
|
|---|
| 46 | potential security risk. Note that this pragma is ignored when the regular
|
|---|
| 47 | expression is obtained from tainted data, i.e. evaluation is always
|
|---|
| 48 | disallowed with tainted regular expressions. See L<perlre/(?{ code })>.
|
|---|
| 49 |
|
|---|
| 50 | For the purpose of this pragma, interpolation of precompiled regular
|
|---|
| 51 | expressions (i.e., the result of C<qr//>) is I<not> considered variable
|
|---|
| 52 | interpolation. Thus:
|
|---|
| 53 |
|
|---|
| 54 | /foo${pat}bar/
|
|---|
| 55 |
|
|---|
| 56 | I<is> allowed if $pat is a precompiled regular expression, even
|
|---|
|
|---|