Skip to content

Commit 9bd8507

Browse files
committed
Better handling of channel names
1 parent 90b5977 commit 9bd8507

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/index.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,14 @@ function Postgres(url, options) {
290290
})
291291
}
292292

293-
function listen(x, fn) {
294-
if (x.match(/[^a-z0-9_-]/))
295-
return Promise.reject('Only a-z A-Z 0-9 and - . _ allowed in channel names')
296-
297-
x in listeners
298-
? listeners[x].push(fn)
299-
: (listeners[x] = [fn])
293+
function listen(channel, fn) {
294+
if (channel in listeners) {
295+
listeners[channel].push(fn)
296+
return Promise.resolve(channel)
297+
}
300298

301-
return query({ raw: true }, getListener(), 'listen "' + x + '"').then(() => x)
299+
listeners[channel] = [fn]
300+
return query({ raw: true }, getListener(), 'listen ' + escape(channel)).then(() => channel)
302301
}
303302

304303
function getListener() {

0 commit comments

Comments
 (0)