diff --git a/autoload/lsp/utils.vim b/autoload/lsp/utils.vim index 28516b40..aceba981 100644 --- a/autoload/lsp/utils.vim +++ b/autoload/lsp/utils.vim @@ -6,7 +6,7 @@ function! s:decode_uri(uri) abort let l:ret = a:uri let l:pos = stridx(l:ret, '?') if l:pos != -1 - let [l:lhs, l:rhs] = [l:ret[: l:pos], l:ret[l:pos :]] + let [l:lhs, l:rhs] = [l:ret[: l:pos], l:ret[l:pos+1 :]] let l:ret = l:lhs . substitute(l:rhs, '+', ' ', 'g') endif return substitute(l:ret, '%\(\x\x\)', '\=printf("%c", str2nr(submatch(1), 16))', 'g') diff --git a/test/lsp/utils.vimspec b/test/lsp/utils.vimspec index 8c9a3a39..a7b1c70a 100644 --- a/test/lsp/utils.vimspec +++ b/test/lsp/utils.vimspec @@ -8,4 +8,39 @@ Describe lsp#utils End End + Describe lsp#utils#uri_to_path + It should return path from uri (Windows) + if !has('win32') + Skip This tests is not for UNIX + endif + let tests = [ + \ {'uri': 'file:///C:/path/to/the/file.txt', 'path': 'C:\path\to\the\file.txt'}, + \ {'uri': 'file:///C:/path/to/the/file+name.txt', 'path': 'C:\path\to\the\file+name.txt'}, + \ {'uri': 'file:///C:/path/to/the/file%2Bname.txt', 'path': 'C:\path\to\the\file+name.txt'}, + \ {'uri': 'file:///C:/path/to/the/file%20name.txt', 'path': 'C:\path\to\the\file name.txt'}, + \ {'uri': 'file:///C:/path+name?query=your+value', 'path': 'C:\path+name?query=your value'}, + \] + for test in tests + let path = lsp#utils#uri_to_path(test.uri) + Assert Equals(path, test.path) + endfor + End + + It should return path from uri (UNIX) + if has('win32') + Skip This tests is not for Windows + endif + let tests = [ + \ {'uri': 'file:///path/to/the/file.txt', 'path': '/path/to/the/file.txt'}, + \ {'uri': 'file:///path/to/the/file+name.txt', 'path': '/path/to/the/file+name.txt'}, + \ {'uri': 'file:///path/to/the/file%2Bname.txt', 'path': '/path/to/the/file+name.txt'}, + \ {'uri': 'file:///path/to/the/file%20name.txt', 'path': '/path/to/the/file name.txt'}, + \ {'uri': 'file:///path+name?query=your+value', 'path': '/path+name?query=your value'}, + \] + for test in tests + let path = lsp#utils#uri_to_path(test.uri) + Assert Equals(path, test.path) + endfor + End + End End