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
if_python3 でスクリプトローカル関数名が UnicodeDecodeError の原因になる #1209
Comments
FunctionObject を作成する際、関数名 --- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -2935,18 +2935,22 @@ FunctionNew(PyTypeObject *subtype, char_u *name, int argc, typval_T *argv,
N_("unnamed function %s does not exist"), name);
return NULL;
}
- self->name = vim_strsave(name);
}
else
- if ((self->name = get_expanded_name(name,
- vim_strchr(name, AUTOLOAD_CHAR) == NULL))
- == NULL)
+ {
+ char_u *p;
+
+ if ((p = get_expanded_name(name,
+ vim_strchr(name, AUTOLOAD_CHAR) == NULL)) == NULL)
{
PyErr_FORMAT(PyExc_ValueError,
N_("function %s does not exist"), name);
return NULL;
}
+ vim_free(p);
+ }
+ self->name = vim_strsave(name);
func_ref(self->name);
self->argc = argc;
self->argv = argv; |
python側で py3 <<EOS
f = vim.Function(b'\x80\xfdR1_f')
EOS |
https://github.com/vim/vim/compare/master...ichizok:fix/py3-vimfunc.diff
|
PRed. |
pが3byte以上あるかチェックしなくてもOKでしょうか? vim/vim@9c7cefc#diff-e30f7b2f6336d31826de211f8f86f376R2951
|
その時点でpはNUL終端文字列であることが確実であるため、3byte以下なら途中で比較が失敗するので問題ないと思います。 |
8.1.0627 |
質問・報告の内容
test.vim
vim -Nu test.vim
Vim関数の PyObject (FunctionObject) の name 属性は、関数名 (C文字列) を
PyUnicode_Decode()
に通した値に設定される。スクリプトローカル関数の場合、関数名は
get_expanded_name()
で変換した形式\x80\xfd
で始まっており、invalid UTF-8 sequence であるため UnicodeDecodeError になる。The text was updated successfully, but these errors were encountered: