Skip to content

Commit

Permalink
Merge pull request RexOps#1506 from ferki/invalid_hostgroup
Browse files Browse the repository at this point in the history
Detect invalid hostgroup expressions
  • Loading branch information
ferki committed Jul 8, 2021
2 parents 805133f + 6f5eae1 commit 9663d7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Revision history for Rex
[API CHANGES]

[BUG FIXES]
- Detect invalid hostgroup expressions

[DOCUMENTATION]

Expand Down
5 changes: 4 additions & 1 deletion lib/Rex/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1786,9 +1786,12 @@ sub evaluate_hostname {
if ( $rule =~ m/,/ ) {
@ret = _evaluate_hostname_list( $start, $rule, $end );
}
else {
elsif ( $rule =~ m/[.]{2}/msx ) {
@ret = _evaluate_hostname_range( $start, $rule, $end );
}
else {
croak('Invalid hostgroup expression');
}

return @ret;
}
Expand Down
8 changes: 7 additions & 1 deletion t/group.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use strict;
use warnings;

use Test::More tests => 97;
use Test::More tests => 98;
use Test::Exception;

use Rex -feature => '0.31';
use Rex::Group;
Expand Down Expand Up @@ -72,3 +73,8 @@ ok( $server->function( $function_name, sub { return $function_result } ),

my $function_ref = qualify_to_ref( $function_name, $server );
is( *{$function_ref}->(), $function_result, 'calling custom function' );

# invalid hostgroup expression

dies_ok( sub { Rex::Commands::evaluate_hostname('s[78]') },
'die on invalid hostgroup expression' );

0 comments on commit 9663d7f

Please sign in to comment.