Skip to content

Commit 9663d7f

Browse files
committed
Merge pull request RexOps#1506 from ferki/invalid_hostgroup
Detect invalid hostgroup expressions
2 parents 805133f + 6f5eae1 commit 9663d7f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Revision history for Rex
44
[API CHANGES]
55

66
[BUG FIXES]
7+
- Detect invalid hostgroup expressions
78

89
[DOCUMENTATION]
910

lib/Rex/Commands.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,9 +1786,12 @@ sub evaluate_hostname {
17861786
if ( $rule =~ m/,/ ) {
17871787
@ret = _evaluate_hostname_list( $start, $rule, $end );
17881788
}
1789-
else {
1789+
elsif ( $rule =~ m/[.]{2}/msx ) {
17901790
@ret = _evaluate_hostname_range( $start, $rule, $end );
17911791
}
1792+
else {
1793+
croak('Invalid hostgroup expression');
1794+
}
17921795

17931796
return @ret;
17941797
}

t/group.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use strict;
22
use warnings;
33

4-
use Test::More tests => 97;
4+
use Test::More tests => 98;
5+
use Test::Exception;
56

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

7374
my $function_ref = qualify_to_ref( $function_name, $server );
7475
is( *{$function_ref}->(), $function_result, 'calling custom function' );
76+
77+
# invalid hostgroup expression
78+
79+
dies_ok( sub { Rex::Commands::evaluate_hostname('s[78]') },
80+
'die on invalid hostgroup expression' );

0 commit comments

Comments
 (0)