Skip to content

Commit

Permalink
Unquote parsed urls in both Workspace and Document (#80)
Browse files Browse the repository at this point in the history
* unquote parsed urls in both Workspace and Document

* Also unquote path used for syspath lookup

* Add test ensuring chars are urldecoded when setting Workspace/Document path

* Unquote before parse, remove unneeded import

* Lint fix
  • Loading branch information
tomv564 authored and gatesn committed Jul 26, 2017
1 parent 327483d commit e0e48fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pyls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit e0e48fb

Please sign in to comment.