mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Correctly parse escaped quotes from hstore.
Parse regexp simplified.
This commit is contained in:
parent
70880dde79
commit
af835f8857
|
@ -523,18 +523,13 @@ class HstoreAdapter(object):
|
|||
|
||||
_re_hstore = regex.compile(r"""
|
||||
# hstore key:
|
||||
"( # catch in quotes
|
||||
(?: # many of
|
||||
[^"] # either not a quote
|
||||
# or a quote escaped, i.e. preceded by an odd number of backslashes
|
||||
| [^\\] (?:\\\\)* \\"
|
||||
)*
|
||||
)"
|
||||
# a string of normal or escaped chars
|
||||
"((?: [^"\\] | \\. )*)"
|
||||
\s*=>\s* # hstore value
|
||||
(?:
|
||||
NULL # the value can be null - not catched
|
||||
# or the same quoted string of the key
|
||||
| "((?:[^"] | [^\\] (?:\\\\)* \\" )*)"
|
||||
# or a quoted string like the key
|
||||
| "((?: [^"\\] | \\. )*)"
|
||||
)
|
||||
(?:\s*,\s*|$) # pairs separated by comma or end of string.
|
||||
""", regex.VERBOSE)
|
||||
|
|
|
@ -168,6 +168,7 @@ class HstoreTestCase(unittest.TestCase):
|
|||
ok('"a"=>"1", "b"=>"2"', {'a': '1', 'b': '2'})
|
||||
ok('"a" => "1" ,"b" => "2"', {'a': '1', 'b': '2'})
|
||||
ok('"a"=>NULL, "b"=>"2"', {'a': None, 'b': '2'})
|
||||
ok(r'"a"=>"\"", "\""=>"2"', {'a': '"', '"': '2'})
|
||||
ok('"a"=>"\'", "\'"=>"2"', {'a': "'", "'": '2'})
|
||||
ok('"a"=>"1", "b"=>NULL', {'a': '1', 'b': None})
|
||||
ok(r'"a\\"=>"1"', {'a\\': '1'})
|
||||
|
|
Loading…
Reference in New Issue
Block a user