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

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

Closed
groig opened this issue Sep 5, 2021 · 2 comments · Fixed by #1538
Closed

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

groig opened this issue Sep 5, 2021 · 2 comments · Fixed by #1538

Comments

@groig
Copy link

groig commented Sep 5, 2021

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: 53e1921
  • Python inside Vim: 3.9.6
@SirVer
Copy link
Owner

SirVer commented Sep 25, 2021

Yep, confirmed.

@groig
Copy link
Author

groig commented Sep 26, 2021

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

yut23 added a commit to yut23/ultisnips that referenced this issue Sep 19, 2023
Both vim and neovim error out if we try to evaluate a string with a null
byte in it. It appears that they use <NL> to represent <Nul> in several
places, so replace any null bytes in text for `vim_helper.eval()` with
newlines.

Fixes: SirVer#1386
yut23 added a commit to yut23/ultisnips that referenced this issue Sep 19, 2023
Both vim and neovim error out if we try to evaluate a string with a null
byte in it. It appears that they use <NL> to represent <Nul> in several
places, so replace any null bytes in text passed to `vim_helper.eval()`
with newlines.

Fixes: SirVer#1386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants