summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-03-13 16:44:29 +0000
committerw0rp <devw0rp@gmail.com>2019-03-13 16:44:29 +0000
commit80ef7ea2d0b22f0d8de7387a3d5bf6e9e5b72e9d (patch)
tree0714ebb7cd67a0b061a2f83e16ebb8593e8a92f2
parent67ea571659f31f2ac2253789fabb6b1a30661508 (diff)
downloadale-80ef7ea2d0b22f0d8de7387a3d5bf6e9e5b72e9d.zip
#2357 Handle Windows paths where the drive letter colon is encoded
-rw-r--r--autoload/ale/path.vim10
-rw-r--r--test/test_path_uri.vader53
2 files changed, 44 insertions, 19 deletions
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim
index 25193ddb..60d42eb5 100644
--- a/autoload/ale/path.vim
+++ b/autoload/ale/path.vim
@@ -205,11 +205,13 @@ function! ale#path#FromURI(uri) abort
let l:encoded_path = a:uri
endif
+ 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:encoded_path =~# '^/[a-zA-Z][:|]'
- let l:encoded_path = substitute(l:encoded_path[1:], '/', '\\', 'g')
- let l:encoded_path = l:encoded_path[0] . ':' . l:encoded_path[2:]
+ if has('win32') && l:path =~# '^/[a-zA-Z][:|]'
+ let l:path = substitute(l:path[1:], '/', '\\', 'g')
+ let l:path = l:path[0] . ':' . l:path[2:]
endif
- return ale#uri#Decode(l:encoded_path)
+ return l:path
endfunction
diff --git a/test/test_path_uri.vader b/test/test_path_uri.vader
index b49d7a5a..cc2287cb 100644
--- a/test/test_path_uri.vader
+++ b/test/test_path_uri.vader
@@ -9,23 +9,46 @@ Execute(ale#path#FromURI should work for Unix paths):
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')
+ if has('win32')
+ 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')
+ else
+ 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')
+ endif
Execute(ale#path#FromURI parse Windows paths with a pipe):
- 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')
+ if has('win32')
+ 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')
+ else
+ 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')
+ endif
+
+Execute(ale#path#FromURI should handle the colon for the drive letter being encoded):
+ " These URIs shouldn't be created, but we'll handle them anyway.
+ if has('win32')
+ AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C%3A/foo/bar/baz.tst')
+ else
+ AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('file:///C%3A/foo/bar/baz.tst')
+ endif
Execute(ale#path#ToURI should work for Unix paths):
AssertEqual 'file:///foo/bar/baz.tst', ale#path#ToURI('/foo/bar/baz.tst')