]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- urls support escaped characters in passwords [ticket:281]
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Aug 2006 18:58:01 +0000 (18:58 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Aug 2006 18:58:01 +0000 (18:58 +0000)
CHANGES
lib/sqlalchemy/engine/url.py
test/engine/parseconnect.py

diff --git a/CHANGES b/CHANGES
index f456647b3586984947d93855870b5c55a54ee2e5..4b8329012201001705cbe8e3dc4b41765b2153d2 100644 (file)
--- 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
index bd8ee26436e68811dd3e42c9c158f8d504b3e2ee..7c3d947ca8b05612a1df5687df986e5527768929 100644 (file)
@@ -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)
index cb77d96d0df955f4ef09d75d06f8c8274b63c16b..9465af684fb72d163dcdc4292309bfd3c190ceb3 100644 (file)
@@ -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