App-GitHooks
view release on metacpan or search on metacpan
lib/App/GitHooks/Config.pm view on Meta::CPAN
{
my ( $self, $section, $name ) = @_;
my $value = $self->get( $section, $name );
return undef
if !defined( $value ) || $value eq '';
my ( $regex ) = $value =~ /^\s*\/(.*?)\/\s*$/;
croak "The key $name in the section $section is not a regex, use /.../ to delimit your expression"
if !defined( $regex );
croak "The key $name in the section $section does not specify a valid regex, it has unescaped '/' delimiters inside it"
if $regex =~ /(?<!\\)\//;
return $regex;
}
=head1 BUGS
Please report any bugs or feature requests through the web interface at
L<https://github.com/guillaumeaubert/App-GitHooks/issues/new>.
lib/App/GitHooks/Utils.pm view on Meta::CPAN
my $project_prefix_regex = get_project_prefix_regex( $app );
$ticket_regex =~ s/\$project_prefixes/$project_prefix_regex/g;
( $ticket_id ) = $branch_name_without_prefixes =~ /$ticket_regex/i;
my $normalize = $config->get( '_', 'normalize_branch_ticket_id' );
if ( defined( $ticket_id ) && defined( $normalize ) && ( $normalize =~ /\S/ ) )
{
my ( $match, $replacement ) = $normalize =~ m|^\s*s/(.*?)(?<!\\)/(.*)/\s*|x;
croak "Invalid format for 'normalize_branch_ticket_id' in configuration file."
if !defined( $match ) || !defined( $replacement );
croak "Unsafe matching pattern in 'normalize_branch_ticket_id', escape your slashes"
if $match =~ /(?<!\\)\//;
croak "Unsafe replacement pattern in 'normalize_branch_ticket_id', escape your slashes"
if $replacement =~ /(?<!\\)\//;
eval( "\$ticket_id =~ s/$match/$replacement/i" ); ## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
}
}
catch
{
carp "ERROR: $_";
};
return $ticket_id;
t/13-Config/20-get_regex.t view on Meta::CPAN
name => 'Empty value.',
config => "$key_name =\n",
expected => undef,
},
{
name => 'Value is not a regex.',
config => "$key_name = test\n",
throws => "The key $key_name in the section _ is not a regex, use /.../ to delimit your expression",
},
{
name => 'Value has unescaped slash delimiters.',
config => "$key_name = /test/test/\n",
throws => "The key $key_name in the section _ does not specify a valid regex, it has unescaped '/' delimiters inside it",
},
{
name => 'Valid regex.',
config => "$key_name = /test/\n",
expected => 'test',
},
];
# Declare tests.
plan( tests => scalar( @$tests + 1 ) );
( run in 0.484 second using v1.01-cache-2.11-cpan-c21f80fb71c )