Skip to content

Commit

Permalink
Ignore catch-all namespace in client connections (Fixes #1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jun 18, 2024
1 parent d67a272 commit 469b7c0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/socketio/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ async def connect(self, url, headers={}, auth=None, transports=None,
if namespaces is None:
namespaces = list(set(self.handlers.keys()).union(
set(self.namespace_handlers.keys())))
if '*' in namespaces:
namespaces.remove('*')
if len(namespaces) == 0:
namespaces = ['/']
elif isinstance(namespaces, str):
Expand Down
2 changes: 2 additions & 0 deletions src/socketio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def connect(self, url, headers={}, auth=None, transports=None,
if namespaces is None:
namespaces = list(set(self.handlers.keys()).union(
set(self.namespace_handlers.keys())))
if '*' in namespaces:
namespaces.remove('*')
if len(namespaces) == 0:
namespaces = ['/']
elif isinstance(namespaces, str):
Expand Down
1 change: 1 addition & 0 deletions tests/async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_connect_default_namespaces(self):
c.eio.connect = AsyncMock()
c.on('foo', mock.MagicMock(), namespace='/foo')
c.on('bar', mock.MagicMock(), namespace='/')
c.on('baz', mock.MagicMock(), namespace='*')
_run(
c.connect(
'url',
Expand Down
1 change: 1 addition & 0 deletions tests/common/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def test_connect_default_namespaces(self):
c.eio.connect = mock.MagicMock()
c.on('foo', mock.MagicMock(), namespace='/foo')
c.on('bar', mock.MagicMock(), namespace='/')
c.on('baz', mock.MagicMock(), namespace='*')
c.connect(
'url',
headers='headers',
Expand Down

0 comments on commit 469b7c0

Please sign in to comment.