Bug#334868: netrw.vim does not handle properly %xx escaping and relative URLs in the file: URL scheme

2005-10-20 Thread Stefano Zacchiroli
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
--- netrw.vim.orig  2005-10-20 14:26:11.0 +0200
+++ /usr/share/vim/vim64/plugin/netrw.vim   2005-10-20 14:24:16.0 
+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())


Bug#334868: netrw.vim does not handle properly %xx escaping and relative URLs in the file: URL scheme

2005-10-20 Thread Stefano Zacchiroli
Body of the previous bug report (which was missing due to a bug in
reportbug :-)

--- CUT HERE ---

Plugin netrw.vim has two issues in the handling of file:// URLs:

1) %xx escaping is not handled properly. For example, opening
   file:///a%20b.txt will result in vim opening something weird since
   the '%' sign will be expanded to the name of the file being opened(!)

   This is an issue expecially with gvim and gnome since the open with
   feature of nautilus escapes spaces and other special characters with
   the '%xx' notation

2) relative URLs are not properly handled. The convention is that 2
   slashes URLs in the file scheme are relative, while those with 3
   slashes are absolute. Thus, for example:

  file://a  - a in the cwd
  file:///a - /a

The attached patch solves both issues implementing:
- URI %xx unescaping
- escaping of special characters for the e: command
- removal of file:// prefix on autocommands

Cheers.

--- CUT HERE ---

-- 
Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
[EMAIL PROTECTED],debian.org,bononia.it} -%- http://www.bononia.it/zack/
If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. -!-


signature.asc
Description: Digital signature