patch 9.1.0686: zip-plugin has problems with special characters Commit: https://github.com/vim/vim/commit/7790ea0c680a9f951a86066e5940ec16b2333c9a Author: Christian Brabandt <c...@256bit.org> Date: Tue Aug 20 22:41:52 2024 +0200
patch 9.1.0686: zip-plugin has problems with special characters Problem: zip-plugin has problems with special characters (user202729) Solution: escape '*?[\' on Unix and handle those chars a bit differently on MS-Windows, add a test, check before overwriting files runtime(zip): small fixes for zip plugin This does the following: - verify the unzip plugin is executable when loading the autoload plugin - handle extracting file names with '[*?\' in its name correctly by escaping those characters for the unzip command (and handle those characters a bit differently on MS-Windows, since the quoting is different) - verify, that the extract plugin is not overwriting a file (could cause a hang, because unzip asking for confirmation) - add a test zip file which contains those special file names fixes: #15505 closes: #15519 Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/Filelist b/Filelist index 9a0cf30ef..803de2ae0 100644 --- a/Filelist +++ b/Filelist @@ -221,6 +221,7 @@ SRC_ALL = \ src/testdir/samples/*.vim \ src/testdir/samples/test000 \ src/testdir/samples/test.zip \ + src/testdir/samples/testa.zip \ src/testdir/color_ramp.vim \ src/testdir/silent.wav \ src/testdir/popupbounce.vim \ diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index 31fb32779..a7a7e579a 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -1,6 +1,6 @@ " zip.vim: Handles browsing zipfiles " AUTOLOAD PORTION -" Date: Aug 05, 2024 +" Date: Aug 18, 2024 " Version: 34 " Maintainer: This runtime file is looking for a new maintainer. " Former Maintainer: Charles E Campbell @@ -12,6 +12,7 @@ " 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 " 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, @@ -73,6 +74,11 @@ if v:version < 901 call s:Mess('WarningMsg', "***warning*** this version of zip needs vim 9.1 or later") finish endif +" sanity checks +if !executable(g:zip_unzipcmd) + call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system") + finish +endif if !dist#vim#IsSafeExecutable('zip', g:zip_unzipcmd) call s:Mess('Error', "Warning: NOT executing " .. g:zip_unzipcmd .. " from current directory!") finish @@ -199,7 +205,7 @@ fun! zip#Read(fname,mode) let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\].*$',' ','') let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\].*\)$',' ','') endif - let fname = substitute(fname, '[', '[[]', 'g') + let fname = fname->substitute('[', '[[]', 'g')->escape('?*\') " sanity check if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) call s:Mess('Error', "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program") @@ -331,9 +337,24 @@ fun! zip#Extract() call s:Mess('Error', "***error*** (zip#Extract) Please specify a file, not a directory") return endif + if filereadable(fname) + call s:Mess('Error', "***error*** (zip#Extract) <" .. fname .."> already exists in directory, not overwriting!") + return + endif + let target = fname->substitute('\[', '[[]', 'g') + if &shell =~ 'cmd' && (has("win32") || has("win64")) + let target = target + \ ->substitute('[?*]', '[&]', 'g') + \ ->substitute('[\]', '?', 'g') + \ ->shellescape() + " there cannot be a file name with '\' in its name, unzip replaces it by _ + let fname = fname->substitute('[\?*]', '_', 'g') + else + let target = target->escape('*?\')->shellescape() + endif " extract the file mentioned under the cursor - call system($"{g:zip_extractcmd} {shellescape(b:zipfile)} {shellescape(fname)}") + call system($"{g:zip_extractcmd} -o {shellescape(b:zipfile)} {target}") if v:shell_error != 0 call s:Mess('Error', "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!") elseif !filereadable(fname) diff --git a/src/testdir/samples/testa.zip b/src/testdir/samples/testa.zip new file mode 100644 index 0000000000000000000000000000000000000000..10b0346e7682e6a40c7d6e890699d4ff65a30703 GIT binary patch literal 1236 zcmajfF;Buk6u|K-1yLYc(Sd=Gu41AefyicD7&MWz3`eBegrp|6LNrQra@5`Emw;Vo z<L*cBE1)6qJ!r2_?np~sVd2O1?jITldOFAODh-Ow>4)&P%*yP_JwNSw?cJlp6{f#V z-W{BvpJ!V7TW4%~YY0IH;rjFWeiH<oRU+`}j^FpE&LtQ)a}GEC&V_F}ZntChT>s4E z)m&_6!S=SdMoPOT>>F@#673qX$G631p<eljY=f@b;w_;&Amb$IR*UEbSb2V9{2S^2 zcEuL<1GqRzHn)k*z#duaPfD8$+XELT(dNX)9^M|mdSy6CoHe>DcD(QfS;)s}o_IkU z4i_IlOI7qm*_GhO@G{tB58vYmGqVWi9)oIff-_A6XLwg9S`;LhiWsRWr$@~fYK9?# zsfdu8a&pxCp{58BR7HGLl~beYF>FG#mpnW_Fcr~JQ%;PULu!V>fvJd%nsQpyG*Wb( W@j{jVJ((rgE0%@VK71{JVeAh@RUZog literal 0 HcmV?d00001 diff --git a/src/testdir/test_zip_plugin.vim b/src/testdir/test_zip_plugin.vim index 3579a4653..e831f2634 100644 --- a/src/testdir/test_zip_plugin.vim +++ b/src/testdir/test_zip_plugin.vim @@ -40,7 +40,8 @@ def Test_zip_basic() execute("normal \<CR>")) ### Check ENTER on file - :1|:/^$//file/ + :1 + search('file.txt') exe ":normal \<cr>" assert_match('zipfile://.*/X.zip::Xzip/file.txt', @%) assert_equal('one', getline(1)) @@ -65,6 +66,10 @@ def Test_zip_basic() :1|:/^$//file/ normal x assert_true(filereadable("Xzip/file.txt")) + + ## Check not overwriting existing file + assert_match('<Xzip/file.txt> .* not overwriting!', execute("normal x")) + delete("Xzip", "rf") ### Check extracting directory @@ -131,5 +136,102 @@ def Test_zip_basic() assert_match('File not readable', execute("e Xnot_exists.zip")) bw +enddef + +def Test_zip_glob_fname() + CheckNotMSWindows + # does not work on Windows, why? + + ### copy sample zip file + if !filecopy("samples/testa.zip", "X.zip") + assert_report("Can't copy samples/testa.zip") + return + endif + defer delete("X.zip") + defer delete('zipglob', 'rf') + + e X.zip + + ### 1) Check extracting strange files + :1 + var fname = 'a[a].txt' + search('\V' .. fname) + normal x + assert_true(filereadable('zipglob/' .. fname)) + delete('zipglob', 'rf') + + :1 + fname = 'a*.txt' + search('\V' .. fname) + normal x + assert_true(filereadable('zipglob/' .. fname)) + delete('zipglob', 'rf') + + :1 + fname = 'a?.txt' + search('\V' .. fname) + normal x + assert_true(filereadable('zipglob/' .. fname)) + delete('zipglob', 'rf') + + :1 + fname = 'a\.txt' + search('\V' .. escape(fname, '\')) + normal x + assert_true(filereadable('zipglob/' .. fname)) + delete('zipglob', 'rf') + + :1 + fname = 'a\.txt' + search('\V' .. escape(fname, '\')) + normal x + assert_true(filereadable('zipglob/' .. fname)) + delete('zipglob', 'rf') + + ### 2) Check entering strange file names + :1 + fname = 'a[a].txt' + search('\V' .. fname) + exe ":normal \<cr>" + assert_match('zipfile://.*/X.zip::zipglob/a\[a\].txt', @%) + assert_equal('a test file with []', getline(1)) + bw + + e X.zip + :1 + fname = 'a*.txt' + search('\V' .. fname) + exe ":normal \<cr>" + assert_match('zipfile://.*/X.zip::zipglob/a\*.txt', @%) + assert_equal('a test file with a*', getline(1)) + bw + + e X.zip + :1 + fname = 'a?.txt' + search('\V' .. fname) + exe ":normal \<cr>" + assert_match('zipfile://.*/X.zip::zipglob/a?.txt', @%) + assert_equal('a test file with a?', getline(1)) + bw + + e X.zip + :1 + fname = 'a\.txt' + search('\V' .. escape(fname, '\')) + exe ":normal \<cr>" + assert_match('zipfile://.*/X.zip::zipglob/a\.txt', @%) + assert_equal('a test file with a\', getline(1)) + bw + e X.zip + :1 + fname = 'a\.txt' + search('\V' .. escape(fname, '\')) + exe ":normal \<cr>" + assert_match('zipfile://.*/X.zip::zipglob/a\\.txt', @%) + assert_equal('a test file with a double \', getline(1)) + bw + + bw enddef diff --git a/src/version.c b/src/version.c index c0f0dff2c..0aa9683eb 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 686, /**/ 685, /**/ -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/E1sgVxT-00EeFM-Ls%40256bit.org.