Fix #2300 - Handle more URIs per RFC 3986
This commit is contained in:
parent
8012e5b60f
commit
a8b987a1c3
2 changed files with 26 additions and 9 deletions
|
@ -197,15 +197,18 @@ function! ale#path#ToURI(path) abort
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#path#FromURI(uri) abort
|
function! ale#path#FromURI(uri) abort
|
||||||
let l:i = len('file://')
|
if a:uri[:6] is? 'file://'
|
||||||
let l:encoded_path = a:uri[: l:i - 1] is# 'file://' ? a:uri[l:i :] : a:uri
|
let l:encoded_path = a:uri[7:]
|
||||||
|
elseif a:uri[:4] is? 'file:'
|
||||||
let l:path = ale#uri#Decode(l:encoded_path)
|
let l:encoded_path = a:uri[5:]
|
||||||
|
else
|
||||||
" If the path is like /C:/foo/bar, it should be C:\foo\bar instead.
|
let l:encoded_path = a:uri
|
||||||
if l:path =~# '^/[a-zA-Z]:'
|
|
||||||
let l:path = substitute(l:path[1:], '/', '\\', 'g')
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return l:path
|
" If the path is like /C:/foo/bar, it should be C:\foo\bar instead.
|
||||||
|
if l:encoded_path =~# '^/[a-zA-Z]:'
|
||||||
|
let l:encoded_path = substitute(l:encoded_path[1:], '/', '\\', 'g')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ale#uri#Decode(l:encoded_path)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
@ -2,8 +2,22 @@ Execute(ale#path#ToURI should work for Windows paths):
|
||||||
AssertEqual 'file:///C:/foo/bar/baz.tst', ale#path#ToURI('C:\foo\bar\baz.tst')
|
AssertEqual 'file:///C:/foo/bar/baz.tst', ale#path#ToURI('C:\foo\bar\baz.tst')
|
||||||
AssertEqual 'foo/bar/baz.tst', ale#path#ToURI('foo\bar\baz.tst')
|
AssertEqual 'foo/bar/baz.tst', ale#path#ToURI('foo\bar\baz.tst')
|
||||||
|
|
||||||
|
Execute(ale#path#FromURI should work for Unix paths):
|
||||||
|
AssertEqual '/foo/bar/baz.tst', ale#path#FromURI('file:///foo/bar/baz.tst')
|
||||||
|
AssertEqual '/foo/bar/baz.tst', ale#path#FromURI('file:/foo/bar/baz.tst')
|
||||||
|
AssertEqual '/foo/bar/baz.tst', ale#path#FromURI('FILE:///foo/bar/baz.tst')
|
||||||
|
AssertEqual '/foo/bar/baz.tst', ale#path#FromURI('FILE:/foo/bar/baz.tst')
|
||||||
|
|
||||||
Execute(ale#path#FromURI should work for Windows paths):
|
Execute(ale#path#FromURI should work for Windows paths):
|
||||||
AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C:/foo/bar/baz.tst')
|
AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C:/foo/bar/baz.tst')
|
||||||
|
AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:/C:/foo/bar/baz.tst')
|
||||||
|
AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:///c:/foo/bar/baz.tst')
|
||||||
|
AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:/c:/foo/bar/baz.tst')
|
||||||
|
AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:///C:/foo/bar/baz.tst')
|
||||||
|
AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:/C:/foo/bar/baz.tst')
|
||||||
|
|
||||||
|
Execute(ale#path#FromURI should handle encoded paths that look like drive letters):
|
||||||
|
AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('file:///C%3A/foo/bar/baz.tst')
|
||||||
|
|
||||||
Execute(ale#path#ToURI should work for Unix paths):
|
Execute(ale#path#ToURI should work for Unix paths):
|
||||||
AssertEqual 'file:///foo/bar/baz.tst', ale#path#ToURI('/foo/bar/baz.tst')
|
AssertEqual 'file:///foo/bar/baz.tst', ale#path#ToURI('/foo/bar/baz.tst')
|
||||||
|
|
Reference in a new issue