From 97f43fbd4f9b05fea5e6ce57e72226bc10fd12a5 Mon Sep 17 00:00:00 2001 From: Varun Chawla Date: Sat, 7 Feb 2026 23:08:45 -0800 Subject: [PATCH] Fix .pgpass file to properly de-escape backslash escapes According to PostgreSQL documentation, backslashes in .pgpass files serve to escape backslashes and colons, and are not part of the value. Previously, asyncpg left escaped values as-is (e.g., `4\:K1` stayed `4\:K1` instead of becoming `4:K1`), which caused authentication failures when passwords contained colons. This fix properly de-escapes: - `\:` becomes `:` - `\\` becomes `\` Fixes #1249 --- asyncpg/connect_utils.py | 9 +++++++-- tests/test_connect.py | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/asyncpg/connect_utils.py b/asyncpg/connect_utils.py index 07c4fdde..4c996fad 100644 --- a/asyncpg/connect_utils.py +++ b/asyncpg/connect_utils.py @@ -123,10 +123,15 @@ def _read_password_file(passfile: pathlib.Path) \ continue # Backslash escapes both itself and the colon, # which is a record separator. + # First, temporarily replace \\ with a placeholder line = line.replace(R'\\', '\n') + # Split on unescaped colons + parts = re.split(r'(?