Skip to content

Escaped bracket not ignored #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cbcoutinho opened this issue Sep 15, 2018 · 8 comments
Open

Escaped bracket not ignored #532

cbcoutinho opened this issue Sep 15, 2018 · 8 comments

Comments

@cbcoutinho
Copy link

Technically a repost of Issue #138 (the second part of the issue was not addressed in #455)

The following snippet incorrectly renders the last bracket as an error:

echo [ \] ]
@phy1729
Copy link
Member

phy1729 commented Sep 15, 2018

What #455 did was remove the attempt to ignore quoted braces. That means both echo [ ] and echo '[ ]' have highlighted brackets. The only way to correctly ignore brackets in quotes would be to basically merge the main and brackets highlighters (e.g. echo "${:-"["}" all are quoted, but it would take parsing the parameter expansion to know there's a new quoting context.)

@cbcoutinho
Copy link
Author

I understand what issue was solved with #455, what I meant was that the OPs second point wasn't addressed by the PR that closed that issue. instead of commenting there I opened a new issue.

@phy1729
Copy link
Member

phy1729 commented Sep 15, 2018

I see what you mean now.

Since both backslash escapes and single quotes are a form of quoting, why should \[ be treated differently than '['?

@cbcoutinho
Copy link
Author

cbcoutinho commented Sep 15, 2018

I can't think of a general rule that satisfies all cases, but here are a couple examples that led me to this issue:

Quoted bracket that should be highlighted, such as executing an SQL query from the command line. In this case highlighting is desired:

$ sqlite mydata.db 'SELECT COUNT(mynumber) AS number FROM mytable;'

Escaped brackets in a regex expression shouldn't be highlighted

grep '\[+' myfile

@danielshahaf
Copy link
Member

More cases for y'all: grep '(foo)', with/without backslashes inside the quotes, with/without -E (in BRE, parentheses are metacharacters when escaped, but in ERE, when unescaped); grep -o \[a-z\]\\+; printf '\e[42;'; bindkey '^[s'.

@phy1729
Copy link
Member

phy1729 commented Sep 22, 2018

I could see adding a case

\\)
(( SOME_VAR )) && pos++
;;

If you want to add that, could you also add a few tests for it?

@cbcoutinho
Copy link
Author

cbcoutinho commented Sep 22, 2018 via email

@phy1729
Copy link
Member

phy1729 commented Sep 22, 2018

There are some docs at https://github.com/zsh-users/zsh-syntax-highlighting/tree/master/tests . If anything is unclear there, please point it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants