Skip to content

Commit

Permalink
expand: regex too greedy (#469)
Browse files Browse the repository at this point in the history
* This version of expand follows standard and does not treat '-' as stdin [1]
* Unfortunately the regex for the -1,2,3 tab-stop form was matching incorrectly because:
  1) zero characters after '-' were allowed (valid usage requires at least 1 digit after dash)
  2) '-' was allowed to appear after the first character
* With this patch, invalid usage "perl expand - -" fails on the first instance of '-'

1. https://pubs.opengroup.org/onlinepubs/007904975/utilities/expand.html
  • Loading branch information
mknos committed Feb 29, 2024
1 parent d54d511 commit 463ca56
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bin/expand
Expand Up @@ -40,7 +40,7 @@ my @tabstops;
my @files;

# at most one argument
if($ARGV[0] =~ /-(.*)/) {
if ($ARGV[0] =~ /\A\-(.+)/) {
@tabstops = split(/,/, $1);
usage(1) if grep /\D/, @tabstops; # only integer arguments are allowed
shift @ARGV;
Expand Down

0 comments on commit 463ca56

Please sign in to comment.