[Bash-completion-devel] [bash-completion-Bugs][312750] _parse_help matches on hyphenated words

bash-completion-bugs at alioth.debian.org bash-completion-bugs at alioth.debian.org
Sun Oct 10 21:40:41 UTC 2010


Bugs item #312750, was changed at 2010-10-10 18:13 by Ville Skyttä 
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=312750&group_id=100114

>Status: Closed
Priority: 3
Submitted By: Stephen Gildea (sgildea-guest)
>Assigned to: Ville Skyttä  (scop-guest)
Summary: _parse_help matches on hyphenated words 
Distribution: --Distribution-Agnostic--
Originally reported in: None
Milestone: None
>Status: Fix Committed
Original bug number: 


Initial Comment:
#! /bin/bash

# This script demonstrates a bug in bash-completion's _parse_help
# function, which will output the first word of a description if it
# contains a hyphen anywhere in it.

option_name=--misc_option
helpful_command() {
  printf '%s\n' "$option_name Comma-separated list of options."
}

. ./bash_completion

output=$(_parse_help helpful_command)
if [ "$output" = "$option_name" ]; then
    echo PASS
    exit 0
else
    echo FAIL
    echo expected:
    echo "$option_name"
    echo actual:
    echo "$output"
    exit 1
fi


The following one-character patch against the current git repository
(1.2+) solves the problem, by anchoring the search for the hyphen in
the first word of the description.


--- bash_completion~	2010-10-09 13:30:08 -0700
+++ bash_completion	2010-10-09 20:39:52 -0700
@@ -678,5 +678,5 @@
 _parse_help() {
     $1 ${2:---help} 2>&1 | command grep -- "^[[:space:]]*-" | tr "," " " | \
-        awk '{print $1; if ($2 ~ /-.*/) { print $2 } }' | sed -e "s:=.*::g"
+        awk '{print $1; if ($2 ~ /^-.*/) { print $2 } }' | sed -e "s:=.*::g"
 }
 

I am also attaching a draft of a new unit test to catch this error,
test/unit/_parse_help.exp


----------------------------------------------------------------------

>Comment By: Ville Skyttä  (scop-guest)
Date: 2010-10-11 00:40

Message:
Applied in git, thanks.

----------------------------------------------------------------------

Comment By: Stephen Gildea (sgildea-guest)
Date: 2010-10-10 18:24

Message:
I am trying again to get the formatting right by using attachments for the script that demonstrates the bug and the one-character patch.

----------------------------------------------------------------------

You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=312750&group_id=100114



More information about the Bash-completion-devel mailing list