highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(Rust) Escaped double quotations in string at attribute are not highlighted properly

Open keiichiw opened this issue 1 year ago • 3 comments

Describe the issue

Escaped double quotations in string at attributes are not treated as a escaped character but a normal quotation.

Which language seems to have the issue?

Rust

Sample Code to Reproduce

#[derive(ThisError)]
enum MyError {
  #[error("\" appears in a string")]
  UnexpectedDoubleQuote
}

fn main() {}

sample at jsfiddle

image

Expected behavior

The escaped double quotation \" shouldn't be treated as a normal double quotation.

keiichiw avatar Jul 10 '23 14:07 keiichiw

Confirm. Looks like a good first issue, probably need to reuse the full string rules inside meta... can ALL the syntactic features of strings be used in a #[] block?

joshgoebel avatar Jul 10 '23 23:07 joshgoebel

{ className: 'string', variants: [ { begin: /b?r(#)"(.|\n)?"\1(?!#)/ }, // Handles raw strings with escaped double quotes { begin: /b?'\?(x\w{2}|u\w{4}|U\w{8}|.)'/ } // Handles character literals with escaped double quotes ] ] }

we should add (.|\")*? to the first variant to match any character or an escaped double quote within the string. we should add (\") to the second variant to allow for escaped double quotation marks within character literals.

update code snippet :

{ className: 'string', variants: [ { begin: /b?r(#)"(.|\")?"\1(?!#)/ }, // Handles raw strings with escaped double quotes { begin: /b?'\?(x\w{2}|u\w{4}|U\w{8}|.|\")'/ } // Handles character literals with escaped double quotes ] }

please correct me if i am wrong.

mohiyaddeen7 avatar Sep 21 '23 13:09 mohiyaddeen7

Very hard to review code here when just thrown in as regular text, but if you'd be game to make a PR I'd be happy to review.

joshgoebel avatar Oct 08 '23 02:10 joshgoebel