Skip to content
Open
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
5 changes: 4 additions & 1 deletion python/ycm/client/base_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ def _ValidateResponseObject( response, response_text ):


def _BuildUri( handler ):
return ToBytes( urljoin( BaseRequest.server_location, handler ) )
request_uri = urljoin( BaseRequest.server_location, handler )
if urlparse( request_uri ).scheme not in ( 'http', 'https' ):
raise RuntimeError( 'Invalid URI scheme. Only http and https are allowed.' )
return ToBytes( request_uri )


def MakeServerException( data ):
Expand Down
16 changes: 14 additions & 2 deletions python/ycm/tests/client/base_request_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from ycm.tests.test_utils import MockVimBuffers, MockVimModule, VimBuffer
MockVimModule()

from hamcrest import assert_that, has_entry
from hamcrest import assert_that, has_entry, equal_to
from unittest import TestCase
from unittest.mock import patch
from ycm.client.base_request import BuildRequestData
from ycm.client.base_request import BuildRequestData, _BuildUri, BaseRequest


class BaseRequestTest( TestCase ):
Expand All @@ -40,3 +40,15 @@ def test_BuildRequestData_AddWorkingDirWithFileName( self, *args ):
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
assert_that( BuildRequestData( current_buffer.number ),
has_entry( 'working_dir', '/some/dir' ) )


def test_BuildUri_ValidScheme( self ):
BaseRequest.server_location = 'http://localhost:1234'
assert_that( _BuildUri( 'handler' ),
equal_to( b'http://localhost:1234/handler' ) )


def test_BuildUri_InvalidScheme( self ):
BaseRequest.server_location = 'http://localhost:1234'
with self.assertRaisesRegex( RuntimeError, 'Invalid URI scheme' ):
_BuildUri( 'file:///etc/passwd' )