Repository navigation
zsh: Don't start a string on an escaped quote - #4282
Open
ShryukGrandhi wants to merge 1 commit into
Open
ShryukGrandhi wants to merge 1 commit into
ShryukGrandhi wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the zsh syntax, an escaped single quote outside of a string (
\') was treated as the start of a single-quoted string. Something likeleft 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 smallconstant.specialCharregion 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 loadszsh.yamland 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 aftergo test ./...: passesgofmt -l pkg/highlight,go vet ./pkg/highlight/: cleanFixes #1309