On Wed, Jul 14, 2021 at 01:49:24PM +0200, Antoine wrote:
> I set up a postgresql server on Windows 10 and connected it using Rust, but
> the Rust client reports invalid UTF-8 data when the password is wrong. I
> use a french locale windows that contain some accents "éèê" etc.
>
> Windows use WTF-16 <https://simonsapin.github.io/wtf-8/> but the Rust
> client asks UTF-8 to the serveur so we think it's a bug from the server to
> not send UTF-8 even if Windows doesn't use it for its locale translation.
This is unfortunately working as designed. The client encoding can't be set
during startup (and authentication is part of it), see
https://github.com/postgres/postgres/blob/master/src/backend/utils/mb/mbutils.c#L85-L88
for more details about it:
> /*
> * During backend startup we can't set client encoding because we (a)
> * can't look up the conversion functions, and (b) may not know the database
> * encoding yet either. So SetClientEncoding() just accepts anything and
> * remembers it for InitializeClientEncoding() to apply later.
> */
The driver should be prepared to receive non UTF-8 messages until
authentication succeeded.