Author: cito
Date: Mon Feb 8 16:23:14 2016
New Revision: 843
Log:
Silently accept unescaped quotes
Modified:
trunk/pgdb.py
trunk/tests/test_dbapi20.py
Modified: trunk/pgdb.py
==============================================================================
--- trunk/pgdb.py Mon Feb 8 16:02:10 2016 (r842)
+++ trunk/pgdb.py Mon Feb 8 16:23:14 2016 (r843)
@@ -799,14 +799,16 @@
The function should be used even when there are no parameters,
so that we have a consistent behavior regarding percent signs.
"""
- if parameters:
- if isinstance(parameters, dict):
- parameters = _quotedict(parameters)
- parameters.quote = self._quote
- else:
- parameters = tuple(map(self._quote, parameters))
+ if not parameters:
+ try:
+ return string % () # unescape literal quotes if possible
+ except (TypeError, ValueError):
+ return string # silently accept unescaped quotes
+ if isinstance(parameters, dict):
+ parameters = _quotedict(parameters)
+ parameters.quote = self._quote
else:
- parameters = {}
+ parameters = tuple(map(self._quote, parameters))
return string % parameters
def _make_description(self, info):
Modified: trunk/tests/test_dbapi20.py
==============================================================================
--- trunk/tests/test_dbapi20.py Mon Feb 8 16:02:10 2016 (r842)
+++ trunk/tests/test_dbapi20.py Mon Feb 8 16:23:14 2016 (r843)
@@ -95,6 +95,8 @@
cur = con.cursor()
cur.execute("select %s, 'a %% sign'", ('a % sign',))
self.assertEqual(cur.fetchone(), ('a % sign', 'a % sign'))
+ cur.execute("select 'a % sign'")
+ self.assertEqual(cur.fetchone(), ('a % sign',))
cur.execute("select 'a %% sign'")
self.assertEqual(cur.fetchone(), ('a % sign',))
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql