Bug#334868: netrw.vim does not handle properly %xx escaping and
relative URLs in the "file:" URL scheme
Stefano Zacchiroli
zack at debian.org
Thu Oct 20 12:36:56 UTC 2005
Package: vim-common
Version: 1:6.4-000+1
Severity: normal
Tags: patch
reportbug-vim-common-20051020-32416-OfnUGW
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.12-1-686
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)
Versions of packages vim-common depends on:
ii vim 1:6.4-000+1 Vi IMproved - enhanced vi editor
vim-common recommends no packages.
-- no debconf information
-------------- next part --------------
--- netrw.vim.orig 2005-10-20 14:26:11.000000000 +0200
+++ /usr/share/vim/vim64/plugin/netrw.vim 2005-10-20 14:24:16.000000000 +0200
@@ -92,8 +92,8 @@
if has("win32")
au BufReadCmd file://* exe "doau BufReadPre ".expand("<afile>")|exe 'e '.substitute(expand("<afile>"),"file:/*","","")|exe "doau BufReadPost ".expand("<afile>")
else
- au BufReadCmd file:///* exe "doau BufReadPre ".expand("<afile>")|exe 'e /'.substitute(expand("<afile>"),"file:/*","","")|exe "doau BufReadPost ".expand("<afile>")
- au BufReadCmd file://localhost/* exe "doau BufReadPre ".expand("<afile>")|exe 'e /'.substitute(expand("<afile>"),"file:/*","","")|exe "doau BufReadPost ".expand("<afile>")
+ au BufReadCmd file://* exe "doau BufReadPre ".expand("<afile>")|exe 'e '.s:ExpandE("<afile>")|exe "doau BufReadPost ".expand("<afile>")
+ au BufReadCmd file://localhost/* exe "doau BufReadPre ".expand("<afile>")|exe 'e '.s:ExpandE("<afile>")|exe "doau BufReadPost ".expand("<afile>")
endif
au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "doau BufReadPre ".expand("<afile>")|exe "Nread 0r ".expand("<afile>")|exe "doau BufReadPost ".expand("<afile>")
au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "doau BufReadPre ".expand("<afile>")|exe "Nread " .expand("<afile>")|exe "doau BufReadPost ".expand("<afile>")
@@ -108,6 +108,53 @@
com! -nargs=* NetUserPass call NetUserPass(<f-args>)
" ------------------------------------------------------------------------
+" ExpandE: expand an argument for :e {{{1
+fun! s:ExpandE(s)
+ let r = a:s
+ let r = expand(r)
+ let r = substitute(r, "file://", "", "")
+ let r = s:UnescapeURI(r)
+ let r = s:EscapeForE(r)
+ return r
+endfun
+
+" UnescapeURI: expand URI escape sequences as per RFC2396 {{{2
+fun! s:UnescapeURI(uri)
+ let i = 0
+ let r = ""
+ while i < strlen(a:uri)
+ if a:uri[i] == "%"
+ let hexs = a:uri[i+1] . a:uri[i+2]
+ if hexs !~ "^\\x\\x$"
+ echoe "Invalid escape sequence \"" . a:uri[i] . hexs . "\""
+ return ""
+ endif
+ let r = r . nr2char("0x" . hexs)
+ let i = i + 3
+ else
+ let r = r . a:uri[i]
+ let i = i + 1
+ endif
+ endwhile
+ return r
+endfun
+
+" EscapeForE: make a string suitable as :e argument {{{2
+fun! s:EscapeForE(s)
+ let i = 0
+ let r = ""
+ while i < strlen(a:s)
+ if a:s[i] !~ "\\w"
+ let r = r . "\\" . a:s[i]
+ else
+ let r = r . a:s[i]
+ endif
+ let i = i + 1
+ endwhile
+ return r
+endfun
+
+" ------------------------------------------------------------------------
" NetSavePosn: saves position of cursor on screen {{{1
fun! s:NetSavePosn()
" call Dfunc("NetSavePosn()")
More information about the pkg-vim-maintainers
mailing list