Skip to content

Commit f77fb0f

Browse files
sqwishyelprans
authored andcommitted
Use _quote_ident to escape channel names.
1 parent 3e6ade6 commit f77fb0f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

asyncpg/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def add_listener(self, channel, callback):
112112
"""
113113
self._check_open()
114114
if channel not in self._listeners:
115-
await self.fetch('LISTEN "{}"'.format(channel))
115+
await self.fetch('LISTEN {}'.format(utils._quote_ident(channel)))
116116
self._listeners[channel] = set()
117117
self._listeners[channel].add(callback)
118118

@@ -127,7 +127,7 @@ async def remove_listener(self, channel, callback):
127127
self._listeners[channel].remove(callback)
128128
if not self._listeners[channel]:
129129
del self._listeners[channel]
130-
await self.fetch('UNLISTEN "{}"'.format(channel))
130+
await self.fetch('UNLISTEN {}'.format(utils._quote_ident(channel)))
131131

132132
def add_log_listener(self, callback):
133133
"""Add a listener for Postgres log messages.

tests/test_listeners.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ async def test_listen_notletters(self):
8787
def listener1(*args):
8888
q1.put_nowait(args)
8989

90-
await con1.add_listener('12+34', listener1)
91-
await con2.execute("""NOTIFY "12+34", 'hello'""")
90+
await con1.add_listener('12+"34', listener1)
91+
await con2.execute("""NOTIFY "12+""34", 'hello'""")
9292

9393
self.assertEqual(
9494
await q1.get(),
95-
(con1, con2.get_server_pid(), '12+34', 'hello'))
95+
(con1, con2.get_server_pid(), '12+"34', 'hello'))
9696

97-
await con1.remove_listener('12+34', listener1)
97+
await con1.remove_listener('12+"34', listener1)
9898

9999
async def test_dangling_listener_warns(self):
100100
async with self.create_pool(database='postgres') as pool:

0 commit comments

Comments
 (0)