Commit: patch 9.2.0984: runtime(zip): cannot adjust zip command line

Christian Brabandt <[email protected]>
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0984: runtime(zip): cannot adjust zip command line

Commit: https://github.com/vim/vim/commit/49bc61c685fd4710f695bc7c7a61add0e9316465
Author: curbe454 <[email protected]>
Date:   Wed Aug 19 21:35:12 2026 +0000

    patch 9.2.0984: runtime(zip): cannot adjust zip command line
    
    Problem:  runtime(zip): cannot adjust zip command line
    Solution: Add support for configuring the options to use, so users could
              optionally make use of 7zip instead of unzip (curbe454)
    
    closes: #20832
    
    Signed-off-by: curbe454 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim
index 61e980743..d016e57d1 100644
--- a/runtime/autoload/zip.vim
+++ b/runtime/autoload/zip.vim
@@ -1,31 +1,10 @@
 " zip.vim: Handles browsing zipfiles
 " AUTOLOAD PORTION
-" Date:		2024 Aug 21
+" Date:		2026 Aug 19
 " Version:	34
 " Maintainer:	This runtime file is looking for a new maintainer.
 " Former Maintainer:	Charles E Campbell
 " Last Change:
-" 2024 Jun 16 by Vim Project: handle whitespace on Windows properly (#14998)
-" 2024 Jul 23 by Vim Project: fix 'x' command
-" 2024 Jul 24 by Vim Project: use delete() function
-" 2024 Jul 30 by Vim Project: fix opening remote zipfile
-" 2024 Aug 04 by Vim Project: escape '[' in name of file to be extracted
-" 2024 Aug 05 by Vim Project: workaround for the FreeBSD's unzip
-" 2024 Aug 05 by Vim Project: clean-up and make it work with shellslash on Windows
-" 2024 Aug 18 by Vim Project: correctly handle special globbing chars
-" 2024 Aug 21 by Vim Project: simplify condition to detect MS-Windows
-" 2025 Mar 11 by Vim Project: handle filenames with leading '-' correctly
-" 2025 Jul 12 by Vim Project: drop ../ on write to prevent path traversal attacks
-" 2025 Sep 22 by Vim Project: support PowerShell Core
-" 2025 Dec 20 by Vim Project: use :lcd instead of :cd
-" 2026 Feb 08 by Vim Project: use system() instead of :!
-" 2026 Mar 08 by Vim Project: Make ZipUpdatePS() check for powershell
-" 2026 Apr 01 by Vim Project: Detect more path traversal attacks
-" 2026 Apr 05 by Vim Project: Detect more path traversal attacks
-" 2026 Apr 14 by Vim Project: Detect more path traversal attacks on Windows
-" 2026 Apr 15 by Vim Project: Detect more path traversal attacks on Windows
-" 2026 Jun 20 by Vim Project: Fix wrong escaping for the powershell calls
-" 2026 Jul 25 by Vim Project: Improved Compatibility for powershell 5 and pwsh 7
 " License:	Vim License  (see vim's :help license)
 " Copyright:	Copyright (C) 2005-2019 Charles E. Campbell {{{1
 "		Permission is hereby granted to use and distribute this code,
@@ -56,12 +35,30 @@ let s:NOTE           = 0
 if !exists("g:zip_zipcmd")
  let g:zip_zipcmd= "zip"
 endif
+if !exists("g:zip_zipcmd_deleteopt")
+ let g:zip_zipcmd_deleteopt= "-d"
+endif
+if !exists("g:zip_zipcmd_updateopt")
+ let g:zip_zipcmd_updateopt= "-u"
+endif
+
 if !exists("g:zip_unzipcmd")
  let g:zip_unzipcmd= "unzip"
 endif
+if !exists("g:zip_unzipcmd_browseopt")
+ let g:zip_unzipcmd_browseopt= "-Z1"
+endif
+if !exists("g:zip_unzipcmd_readopt")
+ let g:zip_unzipcmd_readopt= "-p"
+endif
+
 if !exists("g:zip_extractcmd")
  let g:zip_extractcmd= g:zip_unzipcmd
 endif
+if !exists("g:zip_extractcmd_extractopt")
+ let g:zip_extractcmd_extractopt= "-o"
+endif
+
 if !exists("g:zip_pwsh")
   let g:zip_pwsh=''
 endif
@@ -290,7 +287,7 @@ fun! zip#Browse(zipfile)
  \                '" Select a file with cursor and press ENTER'])
   keepj $
 
-  let gnu_cmd = "keepj sil r! " . g:zip_unzipcmd . " -Z1 -- " . s:Escape(a:zipfile, 1)
+  let gnu_cmd = "keepj sil r! " . g:zip_unzipcmd . " " . g:zip_unzipcmd_browseopt . " -- " . s:Escape(a:zipfile, 1)
   let ps_cmd = 'keepj sil r! ' . s:ZipBrowsePS(a:zipfile)
   call s:TryExecGnuFallBackToPs(g:zip_unzipcmd, gnu_cmd, ps_cmd)
 
@@ -374,7 +371,7 @@ fun! zip#Read(fname,mode)
   let temp = tempname()
   let fn   = expand('%:p')
 
-  let gnu_cmd = g:zip_unzipcmd . ' -p -- ' . s:Escape(zipfile) . ' ' . s:Escape(fname) . ' > ' . s:Escape(temp)
+  let gnu_cmd = g:zip_unzipcmd . ' ' . g:zip_unzipcmd_readopt . ' -- ' . s:Escape(zipfile) . ' ' . s:Escape(fname) . ' > ' . s:Escape(temp)
   let gnu_cmd = 'call system(' . string(gnu_cmd) . ')'
   let ps_cmd = 'call system(' . string(s:ZipReadPS(zipfile, fname, temp)) . ')'
   call s:TryExecGnuFallBackToPs(g:zip_unzipcmd, gnu_cmd, ps_cmd)
@@ -448,7 +445,7 @@ fun! zip#Write(fname)
     endif
   endif
   if fname =~ '^[.]\{1,2}/'
-    let gnu_cmd = g:zip_zipcmd . ' -d ' . s:Escape(fnamemodify(zipfile,":p")) . ' ' . s:Escape(fname)
+    let gnu_cmd = g:zip_zipcmd . ' ' . g:zip_zipcmd_deleteopt . ' ' . s:Escape(fnamemodify(zipfile,":p")) . ' ' . s:Escape(fname)
     let gnu_cmd = 'call system(' . string(gnu_cmd) . ')'
     let ps_cmd = $"call system({string(s:ZipDeleteFilePS(zipfile, fname))})"
     call s:TryExecGnuFallBackToPs(g:zip_zipcmd, gnu_cmd, ps_cmd)
@@ -477,7 +474,7 @@ fun! zip#Write(fname)
     let fname = substitute(fname, '[', '[[]', 'g')
   endif
 
-  let gnu_cmd = g:zip_zipcmd . ' -u '. s:Escape(fnamemodify(zipfile,":p")) . ' ' . s:Escape(fname)
+  let gnu_cmd = g:zip_zipcmd . ' ' . g:zip_zipcmd_updateopt . ' ' . s:Escape(fnamemodify(zipfile,":p")) . ' ' . s:Escape(fname)
   let gnu_cmd = 'call system(''' . substitute(gnu_cmd, "'", "''", 'g') . ''')'
   let zip = fnamemodify(zipfile, ':p')
   let ps_cmd = s:ZipUpdatePS(zip, fname)
@@ -581,7 +578,7 @@ fun! zip#Extract()
   endif
 
   " extract the file mentioned under the cursor
-  let gnu_cmd = g:zip_extractcmd . ' -o '. shellescape(b:zipfile) . ' ' . target
+  let gnu_cmd = g:zip_extractcmd . ' ' . g:zip_extractcmd_extractopt . ' ' . shellescape(b:zipfile) . ' ' . target
   let gnu_cmd = 'call system(' . string(gnu_cmd) . ')'
   let ps_cmd = 'call system(' . string(s:ZipExtractFilePS(b:zipfile, fname)) . ')'
   call s:TryExecGnuFallBackToPs(g:zip_extractcmd, gnu_cmd, ps_cmd)
diff --git a/runtime/doc/pi_zip.txt b/runtime/doc/pi_zip.txt
index 271fc11e9..341e2076f 100644
--- a/runtime/doc/pi_zip.txt
+++ b/runtime/doc/pi_zip.txt
@@ -1,4 +1,4 @@
-*pi_zip.txt*	For Vim version 9.2.  Last change: 2026 Jul 30
+*pi_zip.txt*	For Vim version 9.2.  Last change: 2026 Aug 19
 
 				+====================+
 				| Zip File Interface |
@@ -49,20 +49,30 @@ Copyright: Copyright (C) 2005-2015 Charles E Campbell	 *zip-copyright*
    automatically maximized when opened.
 
 							*g:zip_unzipcmd*
-   Use this option to specify the program which does the duty of "unzip".
-   It's used during browsing. By default: >
+   Use these options to specify the program which does the duty of "unzip" and
+   the required argument switches.
+   It's used during browsing.  By default: >
 	let g:zip_unzipcmd= "unzip"
+	let g:zip_unzipcmd_browseopt= "-Z1"
+	let g:zip_unzipcmd_readopt= "-p"
 <
+   Note: a `--` is appended after the g:zip_unzipcmd_browseopt and
+   g:zip_unzipcmd_readopt settings to indicate the end of options.
+
 							*g:zip_zipcmd*
-   Use this option to specify the program which does the duty of "zip".
+   Use these options to specify the program which does the duty of "zip" and
+   the required argument switches.
    It's used during the writing (updating) of a file already in a zip
    file; by default: >
 	let g:zip_zipcmd= "zip"
+	let g:zip_zipcmd_deleteopt= "-d"
+	let g:zip_zipcmd_updateopt= "-u"
 <
 							*g:zip_extractcmd*
    This option specifies the program (and any options needed) used to
    extract a file from a zip archive.  By default, >
 	let g:zip_extractcmd= g:zip_unzipcmd
+	let g:zip_extractcmd_extractopt= "-o"
 <
 							*g:zip_exec*
    For security reasons, one may prevent that Vim runs executables
diff --git a/src/testdir/test_plugin_zip.vim b/src/testdir/test_plugin_zip.vim
index c46a3efc0..cba7851fe 100644
--- a/src/testdir/test_plugin_zip.vim
+++ b/src/testdir/test_plugin_zip.vim
@@ -16,10 +16,21 @@ def CopyZipFile(source: string)
 enddef
 
 def g:Test_zip_basic()
+  ### Check load once
+  assert_true(!exists("g:loaded_zip"), "Test config: now the zip autoload should not be loaded.")
+
+  ### Windows OS: PowerShell fallback should be manually set up
+  if &shell =~? 'cmd'
+    g:zip_pwsh = 'powershell'
+  endif
+
   CopyZipFile("test.zip")
   defer delete("X.zip")
   e X.zip
 
+  ### Check load once
+  assert_true(exists("g:loaded_zip"))
+
   ### Check header
   assert_match('^" zip\.vim version v\d\+', getline(1))
   assert_match('^" Browsing zipfile .*/X\.zip', getline(2))
@@ -83,6 +94,11 @@ def g:Test_zip_basic()
   assert_equal("X.zip", @%)
   bw
 
+  ### Windows OS: PowerShell fallback
+  if has('win32')
+    return
+  endif
+
   ### Check opening zip when "unzip" program is missing
   var save_zip_unzipcmd = g:zip_unzipcmd
   g:zip_unzipcmd = "/"
@@ -138,6 +154,23 @@ def g:Test_zip_basic()
   bw
 enddef
 
+def g:Test_zip_windows_powershell()
+  CheckMSWindows
+  ### TODO: add more test for powershell fallback
+
+  ### Check opening an no zipfile
+  writefile(["qsdf"], "Xcorupt.zip", "D")
+  e! Xcorupt.zip
+  assert_equal("qsdf", getline(1))
+
+  bw
+
+  ### Check no existing zipfile
+  assert_match('File not readable', execute("e Xnot_exists.zip"))
+
+  bw
+enddef
+
 def g:Test_zip_glob_fname()
   CheckNotMSWindows
   # does not work on Windows, why?
diff --git a/src/version.c b/src/version.c
index cf15655d7..7d8f14d74 100644
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    984,
 /**/
     983,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wwoKL-00CW3D-Ie%40256bit.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.