From a6838a233d051b406baeb9a4c09e50f62bc9f14a Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 28 Jul 2016 23:57:28 -0700 Subject: [PATCH] Do not allow event names with hyphens in them Fixes #36 --- socketio/server.py | 2 ++ tests/test_server.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/socketio/server.py b/socketio/server.py index eceb3a4..613bd4e 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -138,6 +138,8 @@ class Server(object): 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): diff --git a/tests/test_server.py b/tests/test_server.py index 6a373b3..665e3a3 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -45,6 +45,10 @@ class TestServer(unittest.TestCase): 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)