From a8b987a1c31f297622f0038230d23404e7c2ad50 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 21 Feb 2019 19:47:22 +0000 Subject: Fix #2300 - Handle more URIs per RFC 3986 --- autoload/ale/path.vim | 17 ++++++++++------- test/test_path_uri.vader | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim index 89b119f4..ca3afc52 100644 --- a/autoload/ale/path.vim +++ b/autoload/ale/path.vim @@ -197,15 +197,18 @@ function! ale#path#ToURI(path) abort endfunction function! ale#path#FromURI(uri) abort - let l:i = len('file://') - let l:encoded_path = a:uri[: l:i - 1] is# 'file://' ? a:uri[l:i :] : a:uri - - let l:path = ale#uri#Decode(l:encoded_path) + if a:uri[:6] is? 'file://' + let l:encoded_path = a:uri[7:] + elseif a:uri[:4] is? 'file:' + let l:encoded_path = a:uri[5:] + else + let l:encoded_path = a:uri + endif " If the path is like /C:/foo/bar, it should be C:\foo\bar instead. - if l:path =~# '^/[a-zA-Z]:' - let l:path = substitute(l:path[1:], '/', '\\', 'g') + if l:encoded_path =~# '^/[a-zA-Z]:' + let l:encoded_path = substitute(l:encoded_path[1:], '/', '\\', 'g') endif - return l:path + return ale#uri#Decode(l:encoded_path) endfunction diff --git a/test/test_path_uri.vader b/test/test_path_uri.vader index a3e68d98..504aba77 100644 --- a/test/test_path_uri.vader +++ b/test/test_path_uri.vader @@ -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 '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): 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): AssertEqual 'file:///foo/bar/baz.tst', ale#path#ToURI('/foo/bar/baz.tst') -- cgit v1.2.3