[vim/vim] Zip archive explorer plugin incorrectly handles files with spaces in their names (Issue #14998)

13 views
Skip to first unread message

lkintact

unread,
Jun 13, 2024, 8:57:08 PM (14 days ago) Jun 13
to vim/vim, Subscribed

Steps to reproduce

  1. Run gvim.exe arc.zip (arc.zip). gVim opens the archive and places the cursor on its only file, 1 1.txt.
  2. Press Enter. A blank window is shown.

Expected behaviour

The contents of 1 1.txt should be shown.

Version of Vim

9.1.466

Environment

OS: Windows 10 Home
UnZip: 5.51
Terminal: GUI.

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998@github.com>

Christian Brabandt

unread,
Jun 14, 2024, 2:39:15 AM (14 days ago) Jun 14
to vim/vim, Subscribed

hm, works on linux. On Windows I cannot seem to make the zip Plugin working. I guess I am missing an unzip command(?) What does that require?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998/2167327725@github.com>

lkintact

unread,
Jun 14, 2024, 5:26:01 AM (13 days ago) Jun 14
to vim/vim, Subscribed

For the plugin to work I placed unzip.exe (unzip.exe.zip) to $VIM\vimfiles and added this line to my _vimrc: let g:zip_unzipcmd=$VIM .. "\\vimfiles\\unzip.exe".


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998/2167623383@github.com>

Aliaksei Budavei

unread,
Jun 14, 2024, 2:31:22 PM (13 days ago) Jun 14
to vim/vim, Subscribed

Tried with a Wine (9.0) bottle for XP and GVim 7.0,
GnuWin's Unzip-5.51-1, zip.vim (v9, adapted), got:

caution: filename not matched:  1
caution: filename not matched:  1.txt

after doing :edit arc.zip and Entering on the file line.

Wrapping fname in double quotes in zip#Read() does the
trick (unzip.exe -p "C:/users/path/to/arc" "1 1.txt") of
writing 111 to a buffer:

exe 'silent r! '.g:zip_unzipcmd.' -p "'.zipfile.'" "'.fname.'"'

So the s:Escape(fnameescape(fname),1) part should be further
looked into for a newer script version:

https://github.com/vim/vim/blob/8e56747fd26b3b040b6fcbfb6be41b7d5922c6b5/runtime/autoload/zip.vim#L247-L248


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998/2168555954@github.com>

Christian Brabandt

unread,
Jun 14, 2024, 4:30:43 PM (13 days ago) Jun 14
to vim/vim, Subscribed

Interestingly, the command executed on Linux is:

Calling shell to execute: "unzip -p -- '/home/chrisbra/code/vim-upstream/runtime/arc.zip' '1\ 1.txt'"

As far as I can see, this is the correct command to extract a single file using the unzip command. Note, one has to escape the whitespace, because unzip will otherwise try to extract the file "1" and "1.txt", because it splits on whitespace (but it falls back on literal filename matching, if it doesn't find the file specified).

On windows, escapeing the whitespace actually causes the error and one shall not escape the space. I tried the mentioned unzip from above (version 5.51 and a unzip package from msys, which also installs a infozip unzip package, version 6.01). So it seems we need to work-around a bug in unzip here :(

In addition, there is a problem when the shellslash option is set (as I usually do). Then unzip won't find the file obviously.

So all together, I have the following patch now:

diff --git a/zip - Kopie.vim b/zip.vim
index c85c9fa..49e1916 100644
--- a/zip - Kopie.vim
+++ b/zip.vim
@@ -4,6 +4,8 @@
 " Version:     33
 " 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)
 " 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,
@@ -245,7 +247,7 @@ fun! zip#Read(fname,mode)
   let temp = tempname()
 "  call Decho("using temp file<".temp.">")
   let fn   = expand('%:p')
-  exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp
+  exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fname,1).' > '.temp
 "  call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp)
   sil exe 'keepalt file '.temp
   sil keepj e!
@@ -433,6 +435,10 @@ fun! s:Escape(fname,isfilt)
   else
    let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq
   endif
+  if exists("+shellslash") && &shellslash && &shell =~ "cmd.exe"
+   " renormalize directory separator
+   let qnameq=substitute(qnameq, '/', '\\', 'g')
+  endif
 "  call Dret("QuoteFileDir <".qnameq.">")
   return qnameq
 endfun


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998/2168720558@github.com>

Aliaksei Budavei

unread,
Jun 14, 2024, 4:53:27 PM (13 days ago) Jun 14
to vim/vim, Subscribed

These all work in Bash on a Debian box:

unzip -p arc.zip "1 1.txt"
unzip -p arc.zip "1\ 1.txt"
unzip -p arc.zip "1\\ 1.txt"
unzip -p arc.zip '1 1.txt'
unzip -p arc.zip '1\ 1.txt'
unzip -p arc.zip 1\ 1.txt
unzip -p arc.zip 1\\\ 1.txt


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998/2168748444@github.com>

Christian Brabandt

unread,
Jun 14, 2024, 4:55:05 PM (13 days ago) Jun 14
to vim/vim, Subscribed

Try that with an archive that contains "1.txt", "1" and "1 1.txt" :)

The handling of the 2nd parameter is weird at best


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998/2168750221@github.com>

Aliaksei Budavei

unread,
Jun 14, 2024, 5:12:33 PM (13 days ago) Jun 14
to vim/vim, Subscribed

Still, not a problem (and with globbing):

unzip -p arc3.zip '1*'
unzip -p arc3.zip 1\*
unzip -p arc3.zip 1
unzip -p arc3.zip 1.txt
unzip -p arc3.zip 1\ 1.txt


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14998/2168768430@github.com>

Christian Brabandt

unread,
Jun 15, 2024, 8:58:14 AM (12 days ago) Jun 15
to vim/vim, Subscribed

Closed #14998 as completed via 1c67342.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/14998/issue_event/13169064623@github.com>

Reply all
Reply to author
Forward
0 new messages