sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Escape PostgreSQL options

Open V02460 opened this issue 9 months ago • 3 comments

Properly escape PostgreSQL options containing spaces and backslash characters as specified under https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-OPTIONS.

Fixes #2027

Is this a breaking change?

~~No, this change fixes behavior that I consider a minor edge case.~~

Yes,

anyone who's already manually escaping options will get different, likely incorrect, results after this patch

V02460 avatar Mar 21 '25 18:03 V02460

This is technically a breaking behavior change as well, because anyone who's already manually escaping options will get different, likely incorrect, results after this patch.

This should also document that the strings will be escaped: https://github.com/launchbadge/sqlx/blob/e474be6d4b4f7b8a1bbeb65363ef53015feebc47/sqlx-postgres/src/options/mod.rs#L496-L504

Alternatively, we don't do this internally but instead expose PgEscapeOption and direct people to use it. That would be backwards-compatible.

abonander avatar Mar 21 '25 23:03 abonander

Alternatively, we don't do this internally but instead expose PgEscapeOption and direct people to use it. That would be backwards-compatible.

This would leak implementation details and keep a foot gun around, so I’d caution against that.

V02460 avatar Mar 23 '25 13:03 V02460

This would leak implementation details and keep a foot gun around, so I’d caution against that.

  1. It's a detail of the underlying protocol, which can be important to understand.
  2. We could emit a warning log if someone provides a string that isn't properly escaped.
  3. I have learned that silent changes to behavior tend to trip people up regardless, because not everyone reads the CHANGELOG or reads it thoroughly. Hyrum's Law has always held true.
  4. Users who aren't prepared to upgrade to a new major version won't be able to benefit.

If you're fine waiting for this to hit 0.9.0, then it doesn't matter.

abonander avatar Mar 23 '25 21:03 abonander