[vim/vim] yaml syntax does not handle \ characters in multiline strings (Issue #11517)

67 views
Skip to first unread message

Nonoctis

unread,
Nov 7, 2022, 9:31:22 AM11/7/22
to vim/vim, Subscribed

Steps to reproduce

Tested with this snippet:

---
- hosts: localhost
  vars:
    win_shell: |
      Move-Item -Path "C:\OldPath\*.dat" -Destination "C:\NewPath\"

  tasks:
    - debug:
        msg: "{{win_shell}}"

The result is this:
image

Expected behaviour

The syntax should not count \ characters as escaping characters in a multiline string,

Version of Vim

8.2

Environment

WSL 2.0 - Debian 11.5
Windows Terminal
xterm-256color
zsh

Can be reproduced on other distros

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517@github.com>

James Alvarado

unread,
Nov 9, 2022, 1:58:06 PM11/9/22
to vim/vim, Subscribed

I'm also interested in tackling this bug, can I be assigned to this issue as well?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1309220384@github.com>

Christian Brabandt

unread,
Nov 9, 2022, 2:37:21 PM11/9/22
to vim/vim, Subscribed

we do not assign anybody to issues. If you want to check it out, you may have a look at the yaml syntax file @zyx is no longer activer, so any fixes will be appreciated.

But be aware, it may be a bit of a complex issue to fix (you have to know syntax highlighting rules and also regular expressions)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1309263185@github.com>

James Alvarado

unread,
Dec 11, 2022, 12:03:01 AM12/11/22
to vim/vim, Subscribed

I was able to find a regular expression that works for this case but I cannot understand the syntax highlighting rules so I am pasting the regular expression that worked for me if anyone else wants to continue working on this.
(\t+)(.+\|)(\n)((\1\t)(.+)(\n)+)+
Here is the link to my work in progress using regex 101: https://regex101.com/r/KH4cy0/1


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1345458845@github.com>

Christian Brabandt

unread,
Dec 12, 2022, 4:46:57 AM12/12/22
to vim/vim, Subscribed

I tested this out a bit. Is there a reason, not to use single-quote strings here? Since this is about path-names in Windows, single-quotes seem more appropriate anyhow, as you do not want the \ to be considered as an escape character.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1346178700@github.com>

Nonoctis

unread,
Dec 13, 2022, 5:31:36 AM12/13/22
to vim/vim, Subscribed

When you use scalar blocks text is interpreted literally (except for {{ jinja2 }} templates.
Here is a quick playbook you can try:

---
- hosts:
  - localhost
  gather_facts: no
  tasks:
    - debug:
        msg: |
          Let's put some quotes here
          Then some backscaped character\n
          Then some more 'quotes'
          And even "doubl quotes"
          "This line breaks everything\"

    - name: This is where vim breaks
      debug:
        msg: Hello
      when: false

The result I get (using the yaml callback for better readability):
image


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1348150692@github.com>

Christian Brabandt

unread,
Dec 13, 2022, 6:06:07 AM12/13/22
to vim/vim, Subscribed

This seems to be caused by the skip expression in the yamlFlowString definition here:

https://github.com/vim/vim/blob/6342e2c5a6570231aefabd8e34c2f2cb22f6927a/runtime/syntax/yaml.vim#L113-L119

I suppose this is there to allow to add quotes inside double-quoted strings. So to fix this, the following patch seems to work, but I am not sure this is correct, since you may loose the abibility to add quoted double quotes.

diff --git a/runtime/syntax/yaml.vim b/runtime/syntax/yaml.vim
index 49f7d049a..7f36b9a17 100644
--- a/runtime/syntax/yaml.vim
+++ b/runtime/syntax/yaml.vim
@@ -110,13 +110,13 @@ syn match yamlYAMLVersion   '\d\+\.\d\+' contained nextgroup=yamlComment
 execute 'syn match yamlReservedDirective contained nextgroup=yamlComment '.
             \string('%\%(\%(TAG\|YAML\)\s\)\@!'.s:ns_directive_name)

-syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"'
+syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\' end='"'
             \ contains=yamlEscape
             \ nextgroup=yamlKeyValueDelimiter
 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''"  end="'"
             \ contains=yamlSingleEscape
             \ nextgroup=yamlKeyValueDelimiter
-syn match  yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)'
+syn match  yamlEscape contained '\\\%([\\abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)'
 syn match  yamlSingleEscape contained "''"

 syn match yamlBlockScalarHeader contained '\s\+\zs[|>]\%([+-]\=[1-9]\|[1-9]\=[+-]\)\='

So, why do you add the escaped \" in your example?. It looks wrong, there should still be a closing double quote.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1348197537@github.com>

Nonoctis

unread,
Dec 13, 2022, 8:07:57 AM12/13/22
to vim/vim, Subscribed

So, why do you add the escaped \" in your example?. It looks wrong, there should still be a closing double quote.

If my understanding of yaml is correct, it is actually not escaped, text inside a scalar block is literal, like text between single quotes in bash (with the only exception being that jinja templates are expanded), so \" really means the character \ followed by the character ".


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1348508132@github.com>

Christian Brabandt

unread,
Dec 15, 2022, 8:02:15 AM12/15/22
to vim/vim, Subscribed

ah, it's a literal block. I agree, it shouldn't then include the yamlFlowString with escapes. Unfortunately the current syntax file doesn't seem to distinguish literal blocks and it is too hard to follow the logic there and I do not know the language good enough to make an educated guess here :(


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1353029060@github.com>

David Wales

unread,
Feb 29, 2024, 8:03:00 PM2/29/24
to vim/vim, Subscribed

Another example:

example: |
  test='{ example }'
  test2='{ example2 }'
string: 'here'

image.png (view on web)

If you add a space after the =, or remove the space before the } on line two, the highlighting changes.

image.png (view on web)
image.png (view on web)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11517/1972254320@github.com>

Christian Brabandt

unread,
Apr 1, 2024, 8:57:12 AM4/1/24
to vim/vim, Subscribed

Closed #11517 as completed via cc7597c.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/11517/issue_event/12310421825@github.com>

Reply all
Reply to author
Forward
0 new messages