Skip to content

fix(rust): recognize escaped backslash and quote in char literals#4417

Open
sarathfrancis90 wants to merge 1 commit into
highlightjs:mainfrom
sarathfrancis90:fix-rust-escaped-backslash-char-literal
Open

fix(rust): recognize escaped backslash and quote in char literals#4417
sarathfrancis90 wants to merge 1 commit into
highlightjs:mainfrom
sarathfrancis90:fix-rust-escaped-backslash-char-literal

Conversation

@sarathfrancis90

Copy link
Copy Markdown

Resolves #4351

Changes

The Rust char-literal mode listed the escapes \', \w, \xNN, \uNNNN and \UNNNNNNNN, but not the backslash escape \\ (or \"). So a literal like '\\' was read as a lone backslash followed by an escaped closing quote — the literal never terminated and everything after it on the line/file was highlighted as a string.

I added \\ and " to the char.escape alternation so '\\' and '\"' are matched as complete escapes and the literal closes correctly. No other Rust cases are affected.

Checklist

  • Added markup tests (extended test/markup/rust/strings.txt with '\\', '\'' and a line of code after a backslash char literal to prove highlighting no longer leaks)
  • Updated the changelog at CHANGES.md

The Rust char-literal mode listed the escapes \' , \w, \xNN, \uNNNN and
\UNNNNNNNN but not the backslash escape \\ (nor \"). A char literal such as
'\\' was therefore parsed as a stray backslash followed by an escaped closing
quote, so the literal never terminated and every subsequent line was highlighted
as a string.

Add \\ and " to the char.escape alternation so '\\' and '\"' are matched as
complete escapes and the literal closes correctly.

Fixes highlightjs#4351
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.

(Rust) highlighting breaks after backslash char literal ('\\')

1 participant