vim-ruby icon indicating copy to clipboard operation
vim-ruby copied to clipboard

Complex string incorrectly highlights as quoted symbol

Open matthewd opened this issue 3 years ago • 2 comments

Given:

puts("a#{":b"}c")

The inner ": sequence pairs with the opening quote, making a part of a quoted symbol hash key. The #{..} subexpression itself still highlights correctly, but c is not part of any quoted construct (and consequently the closing quote instead starts a new string, messing up the rest of the file).

This feels like it might be unsolvably edge-casey, but I'm regularly astounded by how well this syntax handles very questionable code, so I figured it's at least worth reporting. 🤷🏻‍♂️

I encountered this pattern in the wild in this file: https://github.com/rails/rails/blob/40272988cec849c734ec02cfa89ff830ae019d9e/actionpack/lib/action_controller/metal/strong_parameters.rb#L51

matthewd avatar May 24 '22 14:05 matthewd

No fix yet.

https://github.com/vim-ruby/vim-ruby/blob/55335f2614f914b117f02995340886f409eddc02/syntax/ruby.vim#L474

dkearns avatar May 24 '22 15:05 dkearns

Another example I ran into that hits the same issue, I think:

output: {
  'loglevel' => 'fatal',
  vf: 'scale=\'min(400\, iw):min(400\, ih)\':force_original_aspect_ratio=decrease',
}.freeze,

2022-12-23-202151_1920x1080_scrot

I managed to patch it locally by adding a check for the lack of \ before ', but that's really a workaround

-syn match rubySymbol "'\%(\\.\|[^']\)*'::\@!"he=e-1 contains=rubyQuoteEscape,rubyBackslashEscape,rubySingleQuoteSymbolDelimiter
+syn match rubySymbol "'\%(\\.\|[^\']\)*'::\@!"he=e-1 contains=rubyQuoteEscape,rubyBackslashEscape,rubySingleQuoteSymbolDelimiter

It's weird that it's even trying to highlight ...min(400\, ih)\':force_... as a symbol, it shouldn't be contained inside one. I don't know.

AndrewRadev avatar Dec 23 '22 18:12 AndrewRadev