Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize drive letter in Windows filepaths to uppercase #1772

Merged
merged 3 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions plugin/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def filename_to_uri(file_name: str) -> str:
if file_name.startswith(prefix) and not os.path.exists(file_name):
return _to_resource_uri(file_name, prefix)
path = pathname2url(file_name)
re.sub(r"^([A-Z]):/", _lowercase_driveletter, path)
return urljoin("file:", path)


Expand All @@ -42,7 +41,8 @@ def uri_to_filename(uri: str) -> str:
assert parsed.scheme == "file"
if os.name == 'nt':
# url2pathname does not understand %3A (VS Code's encoding forced on all servers :/)
return url2pathname(parsed.path).strip('\\')
path = url2pathname(parsed.path).strip('\\')
return re.sub(r"^([a-z]):", _uppercase_driveletter, path)
else:
return url2pathname(parsed.path)

Expand Down Expand Up @@ -71,8 +71,8 @@ def _to_resource_uri(path: str, prefix: str) -> str:
return "res://Packages{}".format(quote(path[len(prefix):]))


def _lowercase_driveletter(match: Any) -> str:
def _uppercase_driveletter(match: Any) -> str:
"""
For compatibility with certain other language clients.
For compatibility with Sublime's VCS status in the status bar.
"""
return "{}:/".format(match.group(1).lower())
return "{}:".format(match.group(1).upper())
2 changes: 1 addition & 1 deletion tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_converts_uri_to_path(self):
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
def test_converts_encoded_bad_drive_uri_to_path(self):
# url2pathname does not understand %3A
self.assertEqual("c:\\dir ectory\\file.txt", uri_to_filename("file:///c%3A/dir%20ectory/file.txt"))
self.assertEqual("C:\\dir ectory\\file.txt", uri_to_filename("file:///c%3A/dir%20ectory/file.txt"))


class NixTests(unittest.TestCase):
Expand Down