From 2968f76a74ae51f6a1512e493e4b3a97b1f05d8b Mon Sep 17 00:00:00 2001 From: Martin Natano Date: Tue, 19 Mar 2019 13:42:49 +0100 Subject: [PATCH] Restore support for usernames containing '@' in connection strings. Prior to version 0.18.0 it was possible to have an '@' in a connection string, but that feature got lost when the parsing code was rewritten to support multiple host addresses. --- asyncpg/connect_utils.py | 2 +- tests/test_connect.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/asyncpg/connect_utils.py b/asyncpg/connect_utils.py index 3b5b725e..ee7f8af9 100644 --- a/asyncpg/connect_utils.py +++ b/asyncpg/connect_utils.py @@ -211,7 +211,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user, if not host and parsed.netloc: if '@' in parsed.netloc: - auth, _, hostspec = parsed.netloc.partition('@') + auth, _, hostspec = parsed.netloc.rpartition('@') else: hostspec = parsed.netloc diff --git a/tests/test_connect.py b/tests/test_connect.py index 1ad457ee..27ad4abd 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -402,6 +402,14 @@ class TestConnectParams(tb.TestCase): } ) }, + + { + 'dsn': 'postgresql://some@user@host1/db', + 'result': ([('host1', 5432)], { + 'database': 'db', + 'user': 'some@user', + }) + }, ] @contextlib.contextmanager