Skip to content

Index expansion operators can be escaped when unquoted #7969

Open
@kopischke

Description

Running fish version 3.2.2 (installed via Homebrew) on macOS 11.3 in the stock Terminal.app. I tried fish without third-party customisations by executing sh -c 'env HOME=$(mktemp -d) fish' and checked whether it affected the behaviour I am reporting (it did not).


While exploring some finer points of the fish syntax (still working on that fish syntax plugin for the Nova editor – believe me, nobody’s sorrier than me to keep on coming up with these issues) I have run into a peculiarity of index range expansion I am pretty sure should be considered a bug. Specifically, the index range expansion operators [ and ] can be character escaped if the index range expansion is unquoted:

set range (seq 3)
echo $foo[1]        # => 1
echo $foo\1331\135  # => 1

The second echo statement’s output is both inconsistent with how all other operator-ish characters, paired or not, are treated by fish, and with user expectations as to what escaping should achieve (for instance, echo foo\133bar will output foo[bar, escaping the unpaired bracket syntax error).

Am I correct in assuming this is not intended behaviour? I could model this in my syntax plugin if I must, but this screams “bug” at me …

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions