Skip to content

zsh: Don't start a string on an escaped quote - #4282

Open
ShryukGrandhi wants to merge 1 commit into
micro-editor:masterfrom
ShryukGrandhi:fix/issue-1309-bash-syntax-highlight-qoute-lint
Open

ShryukGrandhi wants to merge 1 commit into
micro-editor:masterfrom
ShryukGrandhi:fix/issue-1309-bash-syntax-highlight-qoute-lint

Conversation

@ShryukGrandhi

Copy link
Copy Markdown

Summary

In the zsh syntax, an escaped single quote outside of a string (\') was treated as the start of a single-quoted string. Something like

printf 'it'\''s a problem'

left everything after it highlighted as a string until the next ', which could be many lines later. This is the case from the original report (the screenshots are of a zsh file).

Changes

  • runtime/syntax/zsh.yaml: add a small constant.specialChar region that starts at a backslash and ends after the next character (or at end of line). This way an escaped quote can't open a string. It is placed before the string regions and only applies outside strings, so a backslash inside '...' still has no special meaning, and a trailing \ used for line continuation doesn't carry over to the next line.
  • pkg/highlight/zsh_test.go: regression test that loads zsh.yaml and checks three things: 'it'\''s' is closed on its line, a line-continuation backslash doesn't leak into the next line, and 'a\' ends at its second quote.

The shell (sh.yaml) problems mentioned later in the thread are a separate issue, and this PR doesn't touch them.

Testing

  • go test ./pkg/highlight/ -run Zsh -v: fails before the change, passes after
  • go test ./...: passes
  • gofmt -l pkg/highlight, go vet ./pkg/highlight/: clean

Fixes #1309

A backslash now consumes the following character, so \' outside of a string is no longer taken as the start of a single-quoted string.

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bash syntax highlight qoute lint

1 participant