diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-28 11:35:57 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-28 11:35:57 -0400 |
commit | 04b66bc5e7b8e8e93d78e9c70a533cd39e367aaf (patch) | |
tree | 5e014b0285328cc1e8b8db0e669326a23cc6a0d0 /lib/sqlalchemy/dialects/postgresql | |
parent | fc348366f76bdb3072c69ad8e03f305de38d486c (diff) | |
download | sqlalchemy-04b66bc5e7b8e8e93d78e9c70a533cd39e367aaf.tar.gz |
Fixed bug in HSTORE type where keys/values that contained
backslashed quotes would not be escaped correctly when
using the "non native" (i.e. non-psycopg2) means
of translating HSTORE data. Patch courtesy Ryan Kelly.
[ticket:2766]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/hstore.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index d7368ff42..c645e25d2 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -68,11 +68,11 @@ def _parse_hstore(hstore_str): pair_match = HSTORE_PAIR_RE.match(hstore_str) while pair_match is not None: - key = pair_match.group('key') + key = pair_match.group('key').replace(r'\"', '"').replace("\\\\", "\\") if pair_match.group('value_null'): value = None else: - value = pair_match.group('value').replace(r'\"', '"') + value = pair_match.group('value').replace(r'\"', '"').replace("\\\\", "\\") result[key] = value pos += pair_match.end() @@ -98,7 +98,7 @@ def _serialize_hstore(val): if position == 'value' and s is None: return 'NULL' elif isinstance(s, util.string_types): - return '"%s"' % s.replace('"', r'\"') + return '"%s"' % s.replace("\\", "\\\\").replace('"', r'\"') else: raise ValueError("%r in %s position is not a string." % (s, position)) |