Hi, Kevin,

On Mon, 15 Mar 2021 07:07:36 -0600
Kevin Locke <ke...@kevinlocke.name> wrote:
>
> I've attached an updated version
> which matches & and | in addition to ; as command separators.  We may
> also want to consider modifying the compgen expression in the same way.

I added this patch (with a changelog entry) to the repository at:

https://salsa.debian.org/debian/bash-completion/-/commits/master

Then I tested it against as much packages as possible:

  # Download packages that have some completion file (get the list from 
apt-file)
  apt-file search "/usr/share/bash-completion/completions" | cut -d ':' -f 1 | 
sort -u | tr '\n' ' ' | xargs apt-get source -y
  
  # Unpack all
  for file in *.deb; do dpkg-deb --extract $file extract/; done

  # Run each package.bash-completion file against a simplified version
  # of the perl script [1] (with and without this change)
  for i in `find -name *.bash-completion`; do echo $i; perl 
/var/tmp/build-root/test-me/root/perl-pre.pl < $i; done > _result.pre
  for i in `find -name *.bash-completion`; do echo $i; perl 
/var/tmp/build-root/test-me/root/perl-pos.pl < $i; done > _result.pos

  # Compare the results
  diff -u1 _result.{pre,pos}
   ./nitrokey-app-1.4.2/debian/nitrokey-app.bash-completion
  -Yes
  +No


So, the change seems to affect nitrokey-app only, which is fine...

Nevertheless, I haven't released this to unstable, because of the
freeze... I'm worried that this change could undesired side-effects
(such as making other packages loose their completions) at this point
of the release cycle, even though the test is telling me it won't.

Let me know your thoughts (about this and/or about the tests I ran).


I'll submit it to experimental, then, once the freeze is lifted, to
unstable.


Cheers,
Gabriel


[1] The simplified version of the modified perl script:

while (<STDIN>) {
        # Get rid of lines containing just spaces or comments.
        chomp;
        s/^\s++//;
        next if /^#/;
        s/\s++$//;

        # We always ignore/permit empty lines
        next if $_ eq '';

        # This is the heart of the script.  Here, we check for some
        # well-known idioms on bash scripts, and try to determine if
        # they're present in the file we're examining.  We assume that
        # if they are, then this means the file is a bash-completion
        # script.
        #
        # The regexes check:
        #
        # - If we're calling the bash function "complete", which is a
        #   pretty common thing to do in bash-completion scripts, or
        #
        # - If we're using the $(program) way of executing a program.
        #   We don't take into account multi-line statements.  Or
        #
        # - If we're calling the bash function "compgen", which is
        #   also a pretty common thing that bash-completion scripts
        #   do.  Or
        #
        # - If we see an "if...then" construction in the file.  We
        #   take into account multi-line statements.
        if (/(^|[|&;])\s*complete.*-[A-Za-z].*/
                || /\$\(.*\)/
                || /\s*compgen.*-[A-Za-z].*/
                || /\s*if.*;.*then/s) {
                print "Yes\n";
                exit 0;
        }
}
print "No\n";
exit 0;

Reply via email to