From a05f1705ae8c8484cc6a234e86e9d11f754a9978 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:25:33 +0800 Subject: [PATCH] nl: numbering type validation (#496) * 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 --- bin/nl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/nl b/bin/nl index acf91ba7..5583c24f 100755 --- a/bin/nl +++ b/bin/nl @@ -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