Skip to content

Commit

Permalink
Sanitize null bytes in eval'ed text (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 authored Sep 25, 2023
1 parent 60240d4 commit f6d1501
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pythonx/UltiSnips/vim_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def command(cmd):

def eval(text):
"""Wraps vim.eval."""
# Replace null bytes with newlines, as vim raises a ValueError and neovim
# treats it as a terminator for the entire command.
text = text.replace("\x00", "\n")
return vim.eval(text)


Expand Down
2 changes: 2 additions & 0 deletions test/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@

COMPL_KW = chr(24) + chr(14)
COMPL_ACCEPT = chr(25)

CTRL_V = chr(22)
23 changes: 23 additions & 0 deletions test/test_Fixes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

from test.vim_test_case import VimTestCase as _VimTest
from test.constant import *

Expand Down Expand Up @@ -125,3 +127,24 @@ class PassThroughNonexecutedTrigger(_VimTest):


# End: #1184


# Tests for https://github.com/SirVer/ultisnips/issues/1386 (embedded null byte)


NULL_BYTE = CTRL_V + "000"


class NullByte_ListSnippets(_VimTest):
snippets = ("word", "never expanded", "", "w")
keys = "foobar" + NULL_BYTE + LS + "\n"
wanted = "foobar\x00\n"


class NullByte_ExpandAfter(_VimTest):
snippets = ("test", "Expand me!", "", "w")
keys = "foobar " + NULL_BYTE + "test" + EX
wanted = "foobar \x00Expand me!"


# End: #1386

0 comments on commit f6d1501

Please sign in to comment.