]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0568: pythoncomplete: g:pythoncomplete_allow_import had no effect v9.2.0568
authorthinca <thinca@gmail.com>
Sun, 31 May 2026 12:33:07 +0000 (12:33 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 31 May 2026 12:33:07 +0000 (12:33 +0000)
Problem:  The security patch 9.2.0561 added a vim.eval() call inside
          Completer.evalsource() to honor g:pythoncomplete_allow_import.
          But the 'vim' module is only imported inside the outer
          vimcomplete() / vimpy3complete() function, not at the script's
          top level, so referring to it from a Completer method raises
          NameError.  The surrounding bare 'except' silently swallows
          the error and leaves allow_imports at 0, meaning the opt-in
          never takes effect -- 'import os' (and any other
          buffer-level import) is always skipped, no candidates are
          produced for 'os.<...>' and
          Test_popup_and_preview_autocommand() fails on the Windows
          CI matrix (Linux skips the test because Python 2 is absent).
Solution: Re-import 'vim' at the top of evalsource() in both
          pythoncomplete.vim and python3complete.vim so the eval reads
          the global, and set g:pythoncomplete_allow_import = 1 in the
          test (it is the opt-in intended for callers that trust the
          buffer contents) (thinca).

closes: #20386

Signed-off-by: thinca <thinca@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/python3complete.vim
runtime/autoload/pythoncomplete.vim
src/testdir/test_popup.vim
src/version.c

index 2b6a6525256ba4e7702fc1edfbf41d1b9863a7a9..0cbfc02ab975059e71f8337bbad33b221f6511d1 100644 (file)
@@ -135,6 +135,9 @@ class Completer(object):
        self.parser = PyParser()
 
     def evalsource(self,text,line=0):
+        # vim is imported locally in vimpy3complete(); re-import here so the
+        # vim.eval() below works (otherwise NameError, silently caught).
+        import vim
         sc = self.parser.parse(text,line)
         try: allow_imports = int(
           vim.eval("get(g:, 'pythoncomplete_allow_import', 0)"))
index 10147767ef96747bb2aeeca2ff354ce8d91130e2..b4340f7ae2d2ca92d52ab228114f26d0f2cd8e4a 100644 (file)
@@ -149,6 +149,9 @@ class Completer(object):
        self.parser = PyParser()
 
     def evalsource(self,text,line=0):
+        # vim is imported locally in vimcomplete(); re-import here so the
+        # vim.eval() below works (otherwise NameError, silently caught).
+        import vim
         sc = self.parser.parse(text,line)
         try: allow_imports = int(
           vim.eval("get(g:, 'pythoncomplete_allow_import', 0)"))
index adead6bac4ae233d8195e664a1eb09af9f1f7a58..cf9cbe166eea877ba67948abd6d82b20eb66d4b0 100644 (file)
@@ -723,6 +723,9 @@ func Test_popup_and_preview_autocommand()
     au!
     au BufAdd * nested tab sball
   augroup END
+  " Let pythoncomplete follow the buffer's 'import os' (off by default
+  " since v9.2.0561) so 'os.' can be completed.
+  let g:pythoncomplete_allow_import = 1
   set omnifunc=pythoncomplete#Complete
   call setline(1, 'import os')
   " make the line long
@@ -745,6 +748,7 @@ func Test_popup_and_preview_autocommand()
   augroup END
   augroup! MyBufAdd
   bw!
+  unlet g:pythoncomplete_allow_import
 endfunc
 
 func s:run_popup_and_previewwindow_dump(lines, dumpfile)
index 56ebd6f0c060fe06b323ca3ca64267439e9b7a64..d9815be705fae50b2c786e2eef76707bb4bfcce4 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    568,
 /**/
     567,
 /**/