Skip to content

Commit

Permalink
Fix DSN parsing regression
Browse files Browse the repository at this point in the history
1d650ed broke certain cases of DSN parsing, fix that.
  • Loading branch information
elprans committed Oct 31, 2018
1 parent e8120c5 commit 8c5c1bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion asyncpg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
# snapshots will automatically include the git revision
# in __version__, for example: '0.16.0.dev0+ge06ad03'

__version__ = '0.18.0'
__version__ = '0.18.1'
13 changes: 7 additions & 6 deletions asyncpg/connect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
else:
hostspec = parsed.netloc

host, port = _parse_hostlist(hostspec, port)
if hostspec:
host, port = _parse_hostlist(hostspec, port)

if parsed.path and database is None:
database = parsed.path
Expand All @@ -234,16 +235,16 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
if isinstance(val, list):
query[key] = val[-1]

if 'host' in query:
val = query.pop('host')
if not host and val:
host, port = _parse_hostlist(val, port)

if 'port' in query:
val = query.pop('port')
if not port and val:
port = [int(p) for p in val.split(',')]

if 'host' in query:
val = query.pop('host')
if not host and val:
host, port = _parse_hostlist(val, port)

if 'dbname' in query:
val = query.pop('dbname')
if database is None:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ class TestConnectParams(tb.TestCase):
'could not match 2 port numbers to 3 hosts'
)
},
{
'dsn': 'postgres://user@?port=56226&host=%2Ftmp',
'result': (
[os.path.join('/tmp', '.s.PGSQL.56226')],
{
'user': 'user',
'database': 'user',
}
)
},
]

@contextlib.contextmanager
Expand Down

0 comments on commit 8c5c1bf

Please sign in to comment.