Changeset 843 for trunk


Ignore:
Timestamp:
Feb 8, 2016, 4:23:14 PM (4 years ago)
Author:
cito
Message:

Silently accept unescaped quotes

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgdb.py

    r842 r843  
    800800        so that we have a consistent behavior regarding percent signs.
    801801        """
    802         if parameters:
    803             if isinstance(parameters, dict):
    804                 parameters = _quotedict(parameters)
    805                 parameters.quote = self._quote
    806             else:
    807                 parameters = tuple(map(self._quote, parameters))
    808         else:
    809             parameters = {}
     802        if not parameters:
     803            try:
     804                return string % ()  # unescape literal quotes if possible
     805            except (TypeError, ValueError):
     806                return string  # silently accept unescaped quotes
     807        if isinstance(parameters, dict):
     808            parameters = _quotedict(parameters)
     809            parameters.quote = self._quote
     810        else:
     811            parameters = tuple(map(self._quote, parameters))
    810812        return string % parameters
    811813
  • trunk/tests/test_dbapi20.py

    r842 r843  
    9696        cur.execute("select %s, 'a %% sign'", ('a % sign',))
    9797        self.assertEqual(cur.fetchone(), ('a % sign', 'a % sign'))
     98        cur.execute("select 'a % sign'")
     99        self.assertEqual(cur.fetchone(), ('a % sign',))
    98100        cur.execute("select 'a %% sign'")
    99101        self.assertEqual(cur.fetchone(), ('a % sign',))
Note: See TracChangeset for help on using the changeset viewer.