summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-20 00:02:33 +0000
committerw0rp <devw0rp@gmail.com>2017-11-21 14:56:37 +0000
commitcf599f4470a7421b01dfd01976274f244894d7e1 (patch)
tree117322fe71dbcce9dbf6db6bcfa7665fc1d1d12d
parente71d831119895daa5474a7aa053a94ed2a9c36da (diff)
downloadale-cf599f4470a7421b01dfd01976274f244894d7e1.zip
#1149 Fix conversion from URIs to filenames on Windows
-rw-r--r--autoload/ale/path.vim9
-rw-r--r--test/test_path_uri.vader3
2 files changed, 11 insertions, 1 deletions
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim
index 83f6e85d..bca0fe81 100644
--- a/autoload/ale/path.vim
+++ b/autoload/ale/path.vim
@@ -185,5 +185,12 @@ 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
- return ale#uri#Decode(l:encoded_path)
+ let l:path = ale#uri#Decode(l:encoded_path)
+
+ " 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')
+ endif
+
+ return l:path
endfunction
diff --git a/test/test_path_uri.vader b/test/test_path_uri.vader
index dbceac3a..a3e68d98 100644
--- a/test/test_path_uri.vader
+++ b/test/test_path_uri.vader
@@ -2,6 +2,9 @@ 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 Windows paths):
+ AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C:/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')
AssertEqual 'foo/bar/baz.tst', ale#path#ToURI('foo/bar/baz.tst')