Skip to content

Fix LISTEN with special characters in channel names#119

Merged
tsloughter merged 2 commits intoerleans:mainfrom
foxfriends:main
Jan 7, 2026
Merged

Fix LISTEN with special characters in channel names#119
tsloughter merged 2 commits intoerleans:mainfrom
foxfriends:main

Conversation

@foxfriends
Copy link
Contributor

By escaping channel names on the way to the database, the listen
function is now able to function with special characters in channel
names, as well as being safe from SQL injection.

The names are NOT quoted when stored in the in-memory listener map,
so that the raw channel names match with the names reported by the
database when the notification occurs.

Closes #118

Provides reproducible example for issue erleans#118: A channel containing
special characters generates invalid SQL due to the pgo not escaping
such identifiers.
By escaping channel names on the way to the database, the `listen`
function is now able to function with special characters in channel
names, as well as being safe from SQL injection.

The names are NOT quoted when stored in the in-memory listener map,
so that the raw channel names match with the names reported by the
database when the notification occurs.

Closes erleans#118
@tsloughter
Copy link
Collaborator

should there not just be quotes?

@foxfriends
Copy link
Contributor Author

https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

This section of the Postgres documentation describes the syntax for identifiers:

Quoted identifiers can contain any character, except the character with code zero. (To include a double quote, write two double quotes.)

@tsloughter
Copy link
Collaborator

Aah, ok. I was then debating if it should be up to the user to do it, but this is safer and I don't think surprising to the user.

@foxfriends
Copy link
Contributor Author

I attempted to do it as the user as it was written, and it didn't work. The database sends the string unescaped back when the notify is triggered, so the library with its pre-escaped string stored in memory cannot match the notification up to the registered listening processes.

@tsloughter
Copy link
Collaborator

Good point. Thanks!

@tsloughter tsloughter merged commit eedeeac into erleans:main Jan 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notifications LISTEN with channel names requiring additional escaping

2 participants