[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 15:24:14 UTC 2010


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

Status: Open
Priority: 3
Submitted By: Stephen Gildea (sgildea-guest)
Assigned to: Nobody (None)
Summary: _parse_help matches on hyphenated words 
Distribution: --Distribution-Agnostic--
Originally reported in: None
Milestone: None
Status: None
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: Stephen Gildea (sgildea-guest)
Date: 2010-10-10 08: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