Skip to content

Commit

Permalink
nl: validate -n option (#446)
Browse files Browse the repository at this point in the history
* Expand input validation code to cover -n option
* As mentioned by the usage string, only 3 values for -n are accepted
* This was found when testing against GNU nl
  • Loading branch information
mknos authored Feb 9, 2024
1 parent 3aacf7c commit 2dd3800
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bin/nl
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,26 @@ my $delim = $options{d} || '\:';
my $type_f = $options{f} || "n";
my $type_h = $options{h} || "n";
my $incr = $options{i};
my $format = $options{n} || "rn";
my $format = $options{n};
my $single_page = $options{p};
my $sep = $options{s} || "\t";
my $startnum = $options{v};
my $width = $options{w};
if (defined $format) {
my %expect = (
'ln' => 1,
'rn' => 1,
'rz' => 1,
);
unless ($expect{$format}) {
warn "$program: invalid line number format: '$format'\n";
exit EX_FAILURE;
}
}
else {
$format = 'rn';
}

if (defined $width) {
if ($width !~ m/\A\+?[0-9]+\Z/ || $width == 0) {
warn "$program: invalid line number field width: '$width'\n";
Expand Down

0 comments on commit 2dd3800

Please sign in to comment.