diff --git a/pyls/workspace.py b/pyls/workspace.py index 3837b037..87473991 100644 --- a/pyls/workspace.py +++ b/pyls/workspace.py @@ -4,7 +4,7 @@ import os import re import sys -from urllib.parse import urlparse, urlunparse +from urllib.parse import urlparse, urlunparse, unquote import jedi @@ -24,7 +24,7 @@ class Workspace(object): M_SHOW_MESSAGE = 'window/showMessage' def __init__(self, root, lang_server=None): - self._url_parsed = urlparse(root) + self._url_parsed = urlparse(unquote(root)) self.root = self._url_parsed.path self._docs = {} self._lang_server = lang_server @@ -36,7 +36,7 @@ def get_document(self, doc_uri): return self._docs[doc_uri] def put_document(self, doc_uri, content, version=None): - path = urlparse(doc_uri).path + path = unquote(urlparse(doc_uri).path) self._docs[doc_uri] = Document( doc_uri, content, sys_path=self.syspath_for_path(path), version=version ) @@ -80,7 +80,7 @@ class Document(object): def __init__(self, uri, source=None, version=None, local=True, sys_path=None): self.uri = uri self.version = version - self.path = urlparse(uri).path + self.path = unquote(urlparse(uri).path) self.filename = os.path.basename(self.path) self._local = local diff --git a/test/test_workspace.py b/test/test_workspace.py index f30afa72..f2ad3065 100644 --- a/test/test_workspace.py +++ b/test/test_workspace.py @@ -51,3 +51,13 @@ def test_non_root_project(pyls): pyls.workspace.put_document(test_uri, 'assert True') test_doc = pyls.workspace.get_document(test_uri) assert project_root in pyls.workspace.syspath_for_path(test_doc.path) + + +def test_urlencoded_paths(): + root_uri = "file:///Encoded%20Space/" + file_uri = root_uri + "test.py" + ws = workspace.Workspace(root_uri) + assert ws.root == "/Encoded Space/" + ws.put_document(file_uri, "") + doc = ws.get_document(file_uri) + assert doc.path == '/Encoded Space/test.py'