# Following is a list of policies to be skipped for severity=4:
#--------------------------------------------------------------
-# There is a stringy eval in Formatter.pm and Tokenizer.pm which is essential
-# for checking user input. So we have to skip this.
-[-BuiltinFunctions::ProhibitStringyEval]
-
# Tidy.pm exports 'perltidy'. Changing this could break existing scripts.
[-Modules::ProhibitAutomaticExportation]
# IOScalar and IOScalarArray need to define a 'print' function
[-Subroutines::ProhibitBuiltinHomonyms]
-# Nested subs are needed for error handling in Tidy.pm.
+# Nested subs are currently needed for error handling in Tidy.pm.
[-Subroutines::ProhibitNestedSubs]
-# Don't require arg unpacking for very short (possibly time-critical) subs.
+# Make adjustment so that we don't require arg unpacking for very short
+# (possibly time-critical) subs.
[Subroutines::RequireArgUnpacking]
short_subroutine_statements = 2
} ## end closure set_bond_strengths
sub bad_pattern {
-
- # See if a pattern will compile. We have to use a string eval here,
- # but it should be safe because the pattern has been constructed
- # by this program.
my ($pattern) = @_;
- my $ok = eval "'##'=~/$pattern/";
- return !defined($ok) || $EVAL_ERROR;
-} ## end sub bad_pattern
+
+ # See if a pattern will compile.
+ # Note: this sub is also called from Tokenizer
+ my $regex = eval { qr/$pattern/ };
+ return $EVAL_ERROR;
+}
{ ## begin closure prepare_cuddled_block_types
return;
} ## end sub Fault
-sub bad_pattern {
-
- # See if a pattern will compile. We have to use a string eval here,
- # but it should be safe because the pattern has been constructed
- # by this program.
- my ($pattern) = @_;
- my $ok = eval "'##'=~/$pattern/";
- return !defined($ok) || $EVAL_ERROR;
-} ## end sub bad_pattern
-
sub make_code_skipping_pattern {
my ( $rOpts, $opt_name, $default ) = @_;
my $param = $rOpts->{$opt_name};
Die("ERROR: the $opt_name parameter '$param' must begin with '#'\n");
}
my $pattern = '^\s*' . $param . '\b';
- if ( bad_pattern($pattern) ) {
+ if ( Perl::Tidy::Formatter::bad_pattern($pattern) ) {
Die(
"ERROR: the $opt_name parameter '$param' causes the invalid regex '$pattern'\n"
);