Unless I'm misinterpreting the specification, it seems like dash doesn't
handle pattern matching in case statements correctly. The following
sample demonstrates the issue:

#!/bin/sh -eu
while read -r line
do
        case "$line" in
                [:space:]*:)
                        echo "a"
                        ;;
                *:)
                        echo "b"
                        ;;
                *)
                        echo "c"
                        ;;
        esac
done <<EOF
libgit2 policy:
  0.27.8-r0:
        lib/apk/db/installed
        https://mirror.sr.ht/alpine/sr.ht/
EOF

The expected output is b a c c, but the output in practice is b b c c.
Quoting the spec:

> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_05
> 
> ...case shall execute the compound-list corresponding to the first one of
> several patterns (see Pattern Matching Notation)...
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
> 
> ...patterns matching a single character shall match a single character:
> ordinary characters, special pattern characters, and pattern bracket
> expressions...
> 
> ...an open bracket... shall introduce a pattern bracket expression... as in
> XBD RE Bracket Expression...
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_05
> 
> ...The following character class expressions shall be supported in all
> locales:
> 
> [:space:]

Am I misinterpreting the spec or is this indeed a problem with dash? In
addition to this issue, the following example cause a parsing error:

        [ \t])

Both problems can be reproduced with bash.

Reply via email to