Skip to content
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

(go) Misunderstands Backslash Character Literals #1411

Closed
wyattallen opened this issue Jan 11, 2017 · 5 comments · Fixed by #2266
Closed

(go) Misunderstands Backslash Character Literals #1411

wyattallen opened this issue Jan 11, 2017 · 5 comments · Fixed by #2266
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community

Comments

@wyattallen
Copy link

In Go, when invoking the escape sequence for backslash in a character literal, HLJS gets stuck incorrectly interpreting the following lines as part of a string. Observe the following simple go program.

package main
import "fmt"
func main() {
  s := "\\"
  c := '\\'
  fmt.Println("Hello, 世界", s, c)
}

When highlighted with HLJS 9.5.0, the entire file following the '\\' is highlighted as a string. It doesn't have this issue with the string literal ("\\").

@joshgoebel
Copy link
Member

Can you confirm this is still and issue and if so perhaps provider a jsfiddle example?

Quick template:
https://jsfiddle.net/ajoshguy/nagkqytv/

@joshgoebel joshgoebel added the needs reproduction Needs a reproducible example or sample label Oct 7, 2019
@wyattallen
Copy link
Author

Still looks broken to me: https://jsfiddle.net/vchkrL3a/

@joshgoebel
Copy link
Member

      {
        className: 'string',
        variants: [
          hljs.QUOTE_STRING_MODE,
          {begin: '\'', end: '[^\\\\]\''},
          {begin: '`', end: '`'},
        ]

We don't seem to think that is valid. The grammar right now says you can't end a string like that... I think it's trying to poorly protect against escaping, but I"m not sure.

@joshgoebel joshgoebel added good first issue Should be easier for first time contributors bug help welcome Could use help from community and removed needs reproduction Needs a reproducible example or sample labels Oct 9, 2019
@joshgoebel
Copy link
Member

That doesn't seem right to me, seems like we should probably use APOS_STRING_MODE there?

  };
  hljs.APOS_STRING_MODE = {
    className: 'string',
    begin: '\'', end: '\'',
    illegal: '\\n',
    contains: [hljs.BACKSLASH_ESCAPE]
  };

@joshgoebel
Copy link
Member

@wyattallen Any chance you could whip up a PR? Looks like go could use some markup tests for strings also.

@joshgoebel joshgoebel changed the title Go Syntax Misunderstands Backslash Character Literals (go) Misunderstands Backslash Character Literals Oct 13, 2019
davidben added a commit to davidben/highlight.js that referenced this issue Nov 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants