From c94a143bfb18f59095963fcde4184a164fd1d1f0 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 30 Jul 2016 15:59:15 +0200 Subject: [PATCH] VIM apparently cannot deal with zero bytes in strings. Fixes #551 --- jedi_vim.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index 1bbba46..9b0f0b7 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -30,10 +30,12 @@ class PythonToVimStr(unicode): __slots__ = [] def __new__(cls, obj, encoding='UTF-8'): - if is_py3 or isinstance(obj, unicode): - return unicode.__new__(cls, obj) - else: - return unicode.__new__(cls, obj, encoding) + if not (is_py3 or isinstance(obj, unicode)): + obj = unicode.__new__(cls, obj, encoding) + + # Vim cannot deal with zero bytes: + obj = obj.replace('\0', '\\0') + return unicode.__new__(cls, obj) def __repr__(self): # this is totally stupid and makes no sense but vim/python unicode