Permalink
Browse files

openbrowser#shellescape(): support other than MS Windows

  • Loading branch information...
1 parent 46b5fd9 commit 5b01f756a57defc75f9882b90a0b0a78a7e70f8b @tyru tyru committed Mar 11, 2013
Showing with 24 additions and 18 deletions.
  1. +24 −18 autoload/openbrowser.vim
View
@@ -246,24 +246,30 @@ endfunction "}}}
" so-called thinca-san escaping ;)
" http://d.hatena.ne.jp/thinca/20100210/1265813598
" NOTE: on MS Windows, invoking cmd.exe via vimproc#system() won't open given URI.
-function! openbrowser#shellescape(uri) "{{{
- let uri = a:uri
- if uri =~# '[&|<>()^"%]'
- " 1. Escape all special characers (& | < > ( ) ^ " %) with hat (^).
- " (Escaping percent (%) keeps hat (^) not to expand)
- let uri = substitute(uri, '[&|<>()^"%]', '^\0', 'g')
- " 2. Escape successive backslashes (\) before double-quote (") with the same number of backslashes.
- let uri = substitute(uri, '\\\+\ze"', '\0\0', 'g')
- " 3. Escape all double-quote (") with backslash (\)
- " (though _"_ has been already escaped by hat (^) , escape it again.
- " thus, double-quote (") becomes backslash + hat + double-quote (\^"))
- let uri = substitute(uri, '"', '\\\0', 'g')
- " 4. Wrap whole string with hat + double-quote (^").
- " (Simply wrapping with _""_ results in _^_ gets invalid)
- let uri = '^"' . uri . '^"'
- endif
- return uri
-endfunction "}}}
+if g:__openbrowser_platform.mswin
+ function! openbrowser#shellescape(uri) "{{{
+ let uri = a:uri
+ if uri =~# '[&|<>()^"%]'
+ " 1. Escape all special characers (& | < > ( ) ^ " %) with hat (^).
+ " (Escaping percent (%) keeps hat (^) not to expand)
+ let uri = substitute(uri, '[&|<>()^"%]', '^\0', 'g')
+ " 2. Escape successive backslashes (\) before double-quote (") with the same number of backslashes.
+ let uri = substitute(uri, '\\\+\ze"', '\0\0', 'g')
+ " 3. Escape all double-quote (") with backslash (\)
+ " (though _"_ has been already escaped by hat (^) , escape it again.
+ " thus, double-quote (") becomes backslash + hat + double-quote (\^"))
+ let uri = substitute(uri, '"', '\\\0', 'g')
+ " 4. Wrap whole string with hat + double-quote (^").
+ " (Simply wrapping with _""_ results in _^_ gets invalid)
+ let uri = '^"' . uri . '^"'
+ endif
+ return uri
+ endfunction "}}}
+else
+ function! openbrowser#shellescape(uri) "{{{
+ return a:uri
+ endfunction "}}}
+endif
" }}}

0 comments on commit 5b01f75

Please sign in to comment.