Skip to content

Commit 5f6dec4

Browse files
committed
fix: normalize WebSocket URI path to prevent /task/service duplication
String concatenation in _get_websocket_uri produced malformed URLs in two cases: - If the URI already contained /task/service, it was appended again - A trailing slash produced a double slash before /task/service Fix: strip trailing slash, check for existing /task/service suffix, then build the final URL with urlunparse instead of string formatting. Added two parametrized test cases covering both failure modes. Resolves #755
1 parent d7b29aa commit 5f6dec4

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/client-python/src/rocketride/mixins/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,12 @@ def _get_websocket_uri(uri: str) -> str:
314314
parsed = urllib.parse.urlparse(normalized)
315315

316316
ws_scheme = 'wss' if parsed.scheme in ('https', 'wss') else 'ws'
317-
ws_uri = parsed._replace(scheme=ws_scheme)
318-
return f'{ws_uri.geturl()}/task/service'
317+
318+
path = parsed.path.rstrip('/')
319+
if not path.endswith('/task/service'):
320+
path = path + '/task/service'
321+
322+
return urllib.parse.urlunparse((ws_scheme, parsed.netloc, path, '', '', ''))
319323

320324
def _set_uri(self, uri: str) -> None:
321325
"""Update the server URI (internal)."""

packages/client-python/tests/RocketRideClient_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,10 @@ async def _check():
23702370
('https://cloud.rocketride.ai', 'wss://cloud.rocketride.ai/task/service'),
23712371
('ws://localhost:5565', 'ws://localhost:5565/task/service'),
23722372
('http://localhost:5565', 'ws://localhost:5565/task/service'),
2373+
# Path already contains /task/service - must not duplicate
2374+
('wss://cloud.rocketride.ai/task/service', 'wss://cloud.rocketride.ai/task/service'),
2375+
# Trailing slash must not produce double slash
2376+
('http://localhost:5565/', 'ws://localhost:5565/task/service'),
23732377
],
23742378
)
23752379
def test_get_websocket_uri_normalization(input_uri: str, expected_uri: str) -> None:

0 commit comments

Comments
 (0)