Skip to content

Commit

Permalink
fix: unlisten channel names with period
Browse files Browse the repository at this point in the history
Similar to a12108a
  • Loading branch information
sk-shishi committed Feb 2, 2023
1 parent 6778dc9 commit eef4ef9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion cjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '""') + '"')
}`
}
}

Expand Down
4 changes: 3 additions & 1 deletion cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
4 changes: 3 additions & 1 deletion deno/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '""') + '"')
}`
}
}

Expand Down
4 changes: 3 additions & 1 deletion deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '""') + '"')
}`
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit eef4ef9

Please sign in to comment.