This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[rt #129336] #!perl -i u erroneously interpreted as -u
authorDan Collins <dcollinsn@gmail.com>
Fri, 23 Sep 2016 05:21:20 +0000 (01:21 -0400)
committerTony Cook <tony@develop-help.com>
Tue, 11 Oct 2016 00:41:15 +0000 (11:41 +1100)
commitf54cfdacff1f3744ef08fc70f1f3bc6c7d862e83
tree558deaa940fb8515c8f9bf7778a45f6ac13ddda4
parent91dca83e9396e920f65b4f093ac7f6e5250a2f43
[rt #129336] #!perl -i u erroneously interpreted as -u

Perl_moreswitches processes a single switch, and returns a pointer
to the start of the next switch. It can return either
the a pointer to the next flag itself:

    #!perl -n -p
               ^ Can point here

Or, to the space before the next "arg":

    #!perl -n -p
             ^ Can point here

(Where the next call to Perl_moreswitches will consume " -".)

In the case of -i[extension], the pointer is by default pointing at
the space after the end of the argument. The current code tries to
do the former, by unconditionally advancing the pointer, and then
advancing it again if it is on a '-'. But that is incorrect:

    #!perl -i p
              ^ Will point here, but that isn't a flag

I could fix this by removing the unconditional s++, and having it
increment by 2 if *(s+1)=='-', but this work isn't actually
necessary - it's better to just leave it pointing at the space after
the argument.
perl.c
t/op/lex.t