]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix query string escaping in engine URLs
authorMiguel Grinberg <miguel.grinberg@gmail.com>
Thu, 21 May 2020 09:54:47 +0000 (05:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 May 2020 18:27:53 +0000 (14:27 -0400)
Fixed issue in :class:`.URL` object where stringifying the object
would not URL encode special characters, preventing the URL from being
re-consumable as a real URL.  Pull request courtesy Miguel Grinberg.

Fixes: #5341
Closes: #5342
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5342
Pull-request-sha: 362ca3398336a3a892e8020530f0c68d4f2d1d01

Change-Id: Ief6218122d1ec0c70479eb1a90e1c16433801924
(cherry picked from commit 2644693c0bf5b775f7a7283cdbf566a37872586f)

doc/build/changelog/unreleased_13/5341.rst [new file with mode: 0644]
lib/sqlalchemy/engine/url.py
test/engine/test_parseconnect.py

diff --git a/doc/build/changelog/unreleased_13/5341.rst b/doc/build/changelog/unreleased_13/5341.rst
new file mode 100644 (file)
index 0000000..28df9cb
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, engine
+    :tickets: 5341
+
+    Fixed issue in :class:`.URL` object where stringifying the object
+    would not URL encode special characters, preventing the URL from being
+    re-consumable as a real URL.  Pull request courtesy Miguel Grinberg.
\ No newline at end of file
index 5950fa0217257be7dc3f1beaa78c08f7db2f0224..7b7a0047ce18089bb17ef2dc868864c02c442474 100644 (file)
@@ -96,7 +96,7 @@ class URL(object):
             keys = list(self.query)
             keys.sort()
             s += "?" + "&".join(
-                "%s=%s" % (k, element)
+                "%s=%s" % (util.quote_plus(k), util.quote_plus(element))
                 for k in keys
                 for element in util.to_list(self.query[k])
             )
index 1277425c150f44985ba5d1bfaed37500bc3fc7b4..77b882f2c19696fbb00c77406a5476604704b1fa 100644 (file)
@@ -147,6 +147,11 @@ class URLTest(fixtures.TestBase):
             "dialect://user:pass@host/db?arg1=param1&arg2=param2&arg2=param3",
         )
 
+        test_url = "dialect://user:pass@host/db?arg1%3D=param1&arg2=param+2"
+        u = url.make_url(test_url)
+        eq_(u.query, {"arg1=": "param1", "arg2": "param 2"})
+        eq_(str(u), test_url)
+
     def test_comparison(self):
         components = (
             "drivername",