Skip to content

Commit

Permalink
Do not allow event names with hyphens in them
Browse files Browse the repository at this point in the history
Fixes #36
  • Loading branch information
miguelgrinberg committed Jul 29, 2016
1 parent a3ae2a9 commit a6838a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions socketio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def message_handler(sid, msg):
client's acknowledgement callback function if it exists. The
``'disconnect'`` handler does not take a second argument.
"""
if '-' in event:
raise ValueError('event names cannot contain hypens')
namespace = namespace or '/'

def set_handler(handler):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def bar():
self.assertEqual(s.handlers['/']['disconnect'], bar)
self.assertEqual(s.handlers['/foo']['disconnect'], bar)

def test_on_bad_event_name(self, eio):
s = server.Server()
self.assertRaises(ValueError, s.on, 'two-words')

def test_emit(self, eio):
mgr = mock.MagicMock()
s = server.Server(client_manager=mgr)
Expand Down

0 comments on commit a6838a2

Please sign in to comment.