ultisnips icon indicating copy to clipboard operation
ultisnips copied to clipboard

Ultisnips crashes when trying to expand a snippet that starts with `^@`

Open groig opened this issue 2 years ago • 2 comments

Ultisnips crashes when trying to expand a snippet that starts with ^@

Expected behavior: Snippet gets expanded or nothing happens

Actual behavior: Ultisnips shows this stacktrace:

An error occured. This is either a bug in UltiSnips or a bug in a
snippet definition. If you think this is a bug, please report it to
https://github.com/SirVer/ultisnips/issues/new
Please read and follow:
https://github.com/SirVer/ultisnips/blob/master/CONTRIBUTING.md#reproducing-bugs

Following is the full stack trace:
Traceback (most recent call last):
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/err_to_scratch_buffer.py", line 44, in wrapper
    return func(self, *args, **kwds)
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet_manager.py", line 173, in expand
    if not self._try_expand():
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet_manager.py", line 794, in _try_expand
    before, snippets = self._can_expand(autotrigger_only)
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet_manager.py", line 790, in _can_expand
    return before, self._snips(before, False, autotrigger_only)
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet_manager.py", line 685, in _snips
    possible_snippets = source.get_snippets(
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet/source/base.py", line 47, in get_snippets
    snips.get_matching_snippets(
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet/source/snippet_dictionary.py", line 40, in get_matching_snippets
    return [s for s in all_snippets if s.matches(trigger, visual_content)]
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet/source/snippet_dictionary.py", line 40, in <listcomp>
    return [s for s in all_snippets if s.matches(trigger, visual_content)]
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/snippet/definition/base.py", line 314, in matches
    match = vim_helper.eval('"%s" =~# "\\\\v.<."' % boundary_chars) != "0"
  File "/home/me/.vim/pack/plugins/start/ultisnips/pythonx/UltiSnips/vim_helper.py", line 123, in eval
    return vim.eval(text)
ValueError: embedded null byte

Steps to reproduce

I have been able to reproduce it without any custom vimrc, just the default config, and Ultisnips and honza/vim-snippets installed vía git clone:

❯ tree -L 4 .vim
.vim
└── pack
    └── plugins
        └── start
            ├── ultisnips
            └── vim-snippets

5 directories, 0 files
  1. Open any file with vim, an empty buffer works too
  2. In insert mode type ^@uuid where ^@ is <C-v><C-2>
  3. Press Tabto expand the snippet

  • Operating System: Arch Linux
  • Vim Version: VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 4 2021 16:54:23) Included patches: 1-3403
  • UltiSnips Version: 53e1921e3ef015ef658e540c0aa9c4835f9c18a6
  • Python inside Vim: 3.9.6

groig avatar Sep 05 '21 01:09 groig

Yep, confirmed.

SirVer avatar Sep 25 '21 19:09 SirVer

FWIW I'm using this as a quick and dirty workaround:

text = text.replace("\x00", "")

inside eval from vim_helper.py. I guess the right solution is something similar but not there in eval

groig avatar Sep 26 '21 19:09 groig