diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-24 11:12:11 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-24 11:23:51 -0400 |
| commit | 2ab67552a097522a82fd250b8b36995a9bc2cd80 (patch) | |
| tree | e4a29ce8190c0141d127f64681690718fffc88b2 /lib/sqlalchemy/engine/url.py | |
| parent | fd3f98ee38b496916122d1a9a29b02d59ca671f9 (diff) | |
| download | sqlalchemy-2ab67552a097522a82fd250b8b36995a9bc2cd80.tar.gz | |
URL parsing fixes
Fixed a long-standing issue with :class:`.URL` where query parameters
following the question mark would not be parsed correctly if the URL did
not contain a database portion with a backslash.
Fixed issue where an ``@`` sign in the database portion of a URL would not
be interpreted correctly if the URL also had a username:password section.
Fixes: #6329
Fixes: #6482
Change-Id: I6cb6478affa49b618335b947a74e64090657a98c
Diffstat (limited to 'lib/sqlalchemy/engine/url.py')
| -rw-r--r-- | lib/sqlalchemy/engine/url.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 7898f9121..f60b9d56d 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -702,16 +702,17 @@ def _parse_rfc1738_args(name): (?P<name>[\w\+]+):// (?: (?P<username>[^:/]*) - (?::(?P<password>.*))? + (?::(?P<password>[^@]*))? @)? (?: (?: - \[(?P<ipv6host>[^/]+)\] | - (?P<ipv4host>[^/:]+) + \[(?P<ipv6host>[^/\?]+)\] | + (?P<ipv4host>[^/:\?]+) )? - (?::(?P<port>[^/]*))? + (?::(?P<port>[^/\?]*))? )? - (?:/(?P<database>.*))? + (?:/(?P<database>[^\?]*))? + (?:\?(?P<query>.*))? """, re.X, ) @@ -719,23 +720,17 @@ def _parse_rfc1738_args(name): m = pattern.match(name) if m is not None: components = m.groupdict() - if components["database"] is not None: - tokens = components["database"].split("?", 2) - components["database"] = tokens[0] - - if len(tokens) > 1: - query = {} - - for key, value in util.parse_qsl(tokens[1]): - if util.py2k: - key = key.encode("ascii") - if key in query: - query[key] = util.to_list(query[key]) - query[key].append(value) - else: - query[key] = value - else: - query = None + if components["query"] is not None: + query = {} + + for key, value in util.parse_qsl(components["query"]): + if util.py2k: + key = key.encode("ascii") + if key in query: + query[key] = util.to_list(query[key]) + query[key].append(value) + else: + query[key] = value else: query = None components["query"] = query |
