From eef4ef9453c325871ab4c2aea609d64a682d5f24 Mon Sep 17 00:00:00 2001 From: Shishi | Shinka Date: Thu, 2 Feb 2023 01:48:03 +0700 Subject: [PATCH] fix: unlisten channel names with period Similar to porsager/postgres@a12108ab7916afa8bf0e451ee61cae47f63cf1af --- cjs/src/index.js | 4 +++- cjs/tests/index.js | 4 +++- deno/src/index.js | 4 +++- deno/tests/index.js | 4 +++- src/index.js | 4 +++- tests/index.js | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cjs/src/index.js b/cjs/src/index.js index b94437ad..1211e416 100644 --- a/cjs/src/index.js +++ b/cjs/src/index.js @@ -192,7 +192,9 @@ function Postgres(a, b) { return delete channels[name] - return sql`unlisten ${ sql(name) }` + return sql`unlisten ${ + sql.unsafe('"' + name.replace(/"/g, '""') + '"') + }` } } diff --git a/cjs/tests/index.js b/cjs/tests/index.js index 985fb086..639fdf5f 100644 --- a/cjs/tests/index.js +++ b/cjs/tests/index.js @@ -785,8 +785,10 @@ t('listen and notify with weird name', async() => { const sql = postgres(options) const channel = 'wat-;.ø.§' const result = await new Promise(async r => { - await sql.listen(channel, r) + const { unlisten } = await sql.listen(channel, r) sql.notify(channel, 'works') + await delay(50) + await unlisten() }) return [ diff --git a/deno/src/index.js b/deno/src/index.js index 8ecb2a17..6fe064f1 100644 --- a/deno/src/index.js +++ b/deno/src/index.js @@ -193,7 +193,9 @@ function Postgres(a, b) { return delete channels[name] - return sql`unlisten ${ sql(name) }` + return sql`unlisten ${ + sql.unsafe('"' + name.replace(/"/g, '""') + '"') + }` } } diff --git a/deno/tests/index.js b/deno/tests/index.js index 688c002b..e04e532c 100644 --- a/deno/tests/index.js +++ b/deno/tests/index.js @@ -787,8 +787,10 @@ t('listen and notify with weird name', async() => { const sql = postgres(options) const channel = 'wat-;.ø.§' const result = await new Promise(async r => { - await sql.listen(channel, r) + const { unlisten } = await sql.listen(channel, r) sql.notify(channel, 'works') + await delay(50) + await unlisten() }) return [ diff --git a/src/index.js b/src/index.js index 9e23b5a2..d9fc597c 100644 --- a/src/index.js +++ b/src/index.js @@ -192,7 +192,9 @@ function Postgres(a, b) { return delete channels[name] - return sql`unlisten ${ sql(name) }` + return sql`unlisten ${ + sql.unsafe('"' + name.replace(/"/g, '""') + '"') + }` } } diff --git a/tests/index.js b/tests/index.js index b990acbc..9c4ab427 100644 --- a/tests/index.js +++ b/tests/index.js @@ -785,8 +785,10 @@ t('listen and notify with weird name', async() => { const sql = postgres(options) const channel = 'wat-;.ø.§' const result = await new Promise(async r => { - await sql.listen(channel, r) + const { unlisten } = await sql.listen(channel, r) sql.notify(channel, 'works') + await delay(50) + await unlisten() }) return [