From: Mike Bayer Date: Tue, 22 Aug 2006 18:58:01 +0000 (+0000) Subject: - urls support escaped characters in passwords [ticket:281] X-Git-Tag: rel_0_2_8~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8d1aecfabe288dcfce3c01bfd87a5a6aff3683c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - urls support escaped characters in passwords [ticket:281] --- diff --git a/CHANGES b/CHANGES index f456647b35..4b83290122 100644 --- a/CHANGES +++ b/CHANGES @@ -27,6 +27,7 @@ flag for use with table reflection to help with quoting rules [ticket:155] - unit tests updated to run without any pysqlite installed; pool test uses a mock DBAPI +- urls support escaped characters in passwords [ticket:281] 0.2.7 - quoting facilities set up so that database-specific quoting can be diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index bd8ee26436..7c3d947ca8 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -1,5 +1,6 @@ import re import cgi +import urllib import sqlalchemy.exceptions as exceptions class URL(object): @@ -19,7 +20,7 @@ class URL(object): if self.username is not None: s += self.username if self.password is not None: - s += ':' + self.password + s += ':' + urllib.quote_plus(self.password) s += "@" if self.host is not None: s += self.host @@ -81,6 +82,8 @@ def _parse_rfc1738_args(name): else: query = None opts = {'username':username,'password':password,'host':host,'port':port,'database':database, 'query':query} + if opts['password'] is not None: + opts['password'] = urllib.unquote_plus(opts['password']) return URL(name, **opts) else: raise exceptions.ArgumentError("Could not parse rfc1738 URL from string '%s'" % name) diff --git a/test/engine/parseconnect.py b/test/engine/parseconnect.py index cb77d96d0d..9465af684f 100644 --- a/test/engine/parseconnect.py +++ b/test/engine/parseconnect.py @@ -21,14 +21,15 @@ class ParseConnectTest(PersistTest): 'dbtype:///E:/work/src/LEM/db/hello.db?foo=bar&hoho=lala', 'dbtype://', 'dbtype://username:password@/db', - 'dbtype:////usr/local/mailman/lists/_xtest@example.com/members.db' + 'dbtype:////usr/local/mailman/lists/_xtest@example.com/members.db', + 'dbtype://username:apples%2Foranges@hostspec/mydatabase', ): u = url.make_url(text) print u, text print "username=", u.username, "password=", u.password, "database=", u.database, "host=", u.host assert u.drivername == 'dbtype' assert u.username == 'username' or u.username is None - assert u.password == 'password' or u.password is None + assert u.password == 'password' or u.password == 'apples/oranges' or u.password is None assert u.host == 'hostspec' or u.host == '127.0.0.1' or (not u.host) assert str(u) == text