mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 13:53:51 -05:00
URL decode FugitiveRemote().path and .user
This is technically backwards incompatible, but I've never seen a remote with URL encoding in practice. (Also I don't think anyone is actually using this function.) One can use .pathname if they need the encoded version.
This commit is contained in:
@@ -80,6 +80,14 @@ function! s:fnameescape(file) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#UrlDecode(str) abort
|
||||||
|
return substitute(a:str, '%\(\x\x\)', '\=iconv(nr2char("0x".submatch(1)), "utf-8", "latin1")', 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:UrlEncode(str) abort
|
||||||
|
return substitute(a:str, '[%#?&;+\<> [:cntrl:]]', '\=printf("%%%02X", char2nr(submatch(0)))', 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:throw(string) abort
|
function! s:throw(string) abort
|
||||||
throw 'fugitive: '.a:string
|
throw 'fugitive: '.a:string
|
||||||
endfunction
|
endfunction
|
||||||
@@ -1315,15 +1323,15 @@ endfunction
|
|||||||
function! s:UrlParse(url) abort
|
function! s:UrlParse(url) abort
|
||||||
let scp_authority = matchstr(a:url, '^[^:/]\+\ze:\%(//\)\@!')
|
let scp_authority = matchstr(a:url, '^[^:/]\+\ze:\%(//\)\@!')
|
||||||
if len(scp_authority) && !(has('win32') && scp_authority =~# '^\a:[\/]')
|
if len(scp_authority) && !(has('win32') && scp_authority =~# '^\a:[\/]')
|
||||||
let url = {'scheme': 'ssh', 'authority': scp_authority, 'hash': '',
|
let url = {'scheme': 'ssh', 'authority': s:UrlEncode(scp_authority), 'hash': '',
|
||||||
\ 'path': substitute(strpart(a:url, len(scp_authority) + 1), '[#?]', '\=printf("%%%02X", char2nr(submatch(0)))', 'g')}
|
\ 'path': s:UrlEncode(strpart(a:url, len(scp_authority) + 1))}
|
||||||
elseif empty(a:url)
|
elseif empty(a:url)
|
||||||
let url = {'scheme': '', 'authority': '', 'path': '', 'hash': ''}
|
let url = {'scheme': '', 'authority': '', 'path': '', 'hash': ''}
|
||||||
else
|
else
|
||||||
let match = matchlist(a:url, '^\([[:alnum:].+-]\+\)://\([^/]*\)\(/[^#]*\)\=\(#.*\)\=$')
|
let match = matchlist(a:url, '^\([[:alnum:].+-]\+\)://\([^/]*\)\(/[^#]*\)\=\(#.*\)\=$')
|
||||||
if empty(match)
|
if empty(match)
|
||||||
let url = {'scheme': 'file', 'authority': '', 'hash': '',
|
let url = {'scheme': 'file', 'authority': '', 'hash': '',
|
||||||
\ 'path': substitute(a:url, '[#?]', '\=printf("%%%02X", char2nr(submatch(0)))', 'g')}
|
\ 'path': s:UrlEncode(a:url)}
|
||||||
else
|
else
|
||||||
let url = {'scheme': match[1], 'authority': match[2], 'hash': match[4]}
|
let url = {'scheme': match[1], 'authority': match[2], 'hash': match[4]}
|
||||||
let url.path = empty(match[3]) ? '/' : match[3]
|
let url.path = empty(match[3]) ? '/' : match[3]
|
||||||
@@ -1335,7 +1343,7 @@ endfunction
|
|||||||
function! s:UrlPopulate(string, into) abort
|
function! s:UrlPopulate(string, into) abort
|
||||||
let url = a:into
|
let url = a:into
|
||||||
let url.protocol = substitute(url.scheme, '.\zs$', ':', '')
|
let url.protocol = substitute(url.scheme, '.\zs$', ':', '')
|
||||||
let url.user = matchstr(url.authority, '.\{-\}\ze@', '', '')
|
let url.user = fugitive#UrlDecode(matchstr(url.authority, '.\{-\}\ze@', '', ''))
|
||||||
let url.host = substitute(url.authority, '.\{-\}@', '', '')
|
let url.host = substitute(url.authority, '.\{-\}@', '', '')
|
||||||
let url.hostname = substitute(url.host, ':\d\+$', '', '')
|
let url.hostname = substitute(url.host, ':\d\+$', '', '')
|
||||||
let url.port = matchstr(url.host, ':\zs\d\+$', '', '')
|
let url.port = matchstr(url.host, ':\zs\d\+$', '', '')
|
||||||
@@ -1354,6 +1362,7 @@ function! s:UrlPopulate(string, into) abort
|
|||||||
else
|
else
|
||||||
let url.href = a:string
|
let url.href = a:string
|
||||||
endif
|
endif
|
||||||
|
let url.path = fugitive#UrlDecode(matchstr(url.path, '^[^?]*'))
|
||||||
let url.url = matchstr(url.href, '^[^#]*')
|
let url.url = matchstr(url.href, '^[^#]*')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user