Skip to content

Commit 0cd7681

Browse files
committed
Fix %-encoding in UriToFilePath
In #1119 a change was made to "unquote" the URI before converting to a file path, ostensibly to support windows. It seems that either that change was broken, or that Python standard library has since been fixed and this has caused legitimate %-encoded paths (like foo#bar/test.c) to now truncate at the #. The tests added for UriToFilePath with Windows paths still pass unchanged without the hack on Python 3.14 so I'm happy to just remove the hack.
1 parent bd0d133 commit 0cd7681

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

ycmd/completers/language_server/language_server_protocol.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import os
2020
import json
2121
import hashlib
22-
from urllib.parse import urljoin, urlparse, unquote
22+
from urllib.parse import urljoin, urlparse
2323
from urllib.request import pathname2url, url2pathname
2424

2525
from ycmd.utils import ( ByteOffsetToCodepointOffset,
@@ -767,8 +767,7 @@ def UriToFilePath( uri ):
767767
# whereas
768768
# url2pathname('/C:/') == 'C:\\'
769769
# Therefore first unquote pathname.
770-
pathname = unquote( parsed_uri.path )
771-
return os.path.abspath( url2pathname( pathname ) )
770+
return os.path.abspath( url2pathname( uri, require_scheme=True ) )
772771

773772

774773
def _BuildMessageData( message ):

ycmd/tests/language_server/language_server_protocol_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def test_UriToFilePath_Unix( self ):
153153
equal_to( '/usr/local/test/test.test' ) )
154154
assert_that( lsp.UriToFilePath( 'file:///usr/local/test/test.test' ),
155155
equal_to( '/usr/local/test/test.test' ) )
156+
assert_that( lsp.UriToFilePath( 'file:///usr/local/test%23foo/test.test' ),
157+
equal_to( '/usr/local/test#foo/test.test' ) )
156158

157159

158160
@WindowsOnly

0 commit comments

Comments
 (0)