Skip to content

Commit

Permalink
nl: numbering type validation (#496)
Browse files Browse the repository at this point in the history
* As outlined in usage string, the valid line numbering types for options -b/-f/-h are a/t/n/pexpr/eexpr
* 1st character of value gets split into "type" list; add validation around this at start of program
* Invalid usage example: perl nl -b a -f n -h o
  • Loading branch information
mknos committed Mar 12, 2024
1 parent 773202d commit a05f170
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bin/nl
Expand Up @@ -109,6 +109,20 @@ my $regex_h = "";
($type_h, $regex_h) = split //, $type_h, 2;

my @type = ($type_h, $type_b, $type_f,); # don't change order
for (@type) {
my %expect = (
'a' => 1,
't' => 1,
'n' => 1,
'p' => 1,
'e' => 1,
);
unless ($expect{$_}) {
warn "$program: invalid numbering style: '$_'\n";
pod2usage(EX_FAILURE);
}
}

my @regex = ($regex_h, $regex_b, $regex_f); # don't change order

# options -d
Expand Down

0 comments on commit a05f170

Please sign in to comment.