mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-05-03 14:43:42 +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"""
|
_re_hstore = regex.compile(r"""
|
||||||
# hstore key:
|
# hstore key:
|
||||||
"( # catch in quotes
|
# a string of normal or escaped chars
|
||||||
(?: # many of
|
"((?: [^"\\] | \\. )*)"
|
||||||
[^"] # either not a quote
|
|
||||||
# or a quote escaped, i.e. preceded by an odd number of backslashes
|
|
||||||
| [^\\] (?:\\\\)* \\"
|
|
||||||
)*
|
|
||||||
)"
|
|
||||||
\s*=>\s* # hstore value
|
\s*=>\s* # hstore value
|
||||||
(?:
|
(?:
|
||||||
NULL # the value can be null - not catched
|
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.
|
(?:\s*,\s*|$) # pairs separated by comma or end of string.
|
||||||
""", regex.VERBOSE)
|
""", 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" => "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('"a"=>NULL, "b"=>"2"', {'a': None, 'b': '2'})
|
||||||
|
ok(r'"a"=>"\"", "\""=>"2"', {'a': '"', '"': '2'})
|
||||||
ok('"a"=>"\'", "\'"=>"2"', {'a': "'", "'": '2'})
|
ok('"a"=>"\'", "\'"=>"2"', {'a': "'", "'": '2'})
|
||||||
ok('"a"=>"1", "b"=>NULL', {'a': '1', 'b': None})
|
ok('"a"=>"1", "b"=>NULL', {'a': '1', 'b': None})
|
||||||
ok(r'"a\\"=>"1"', {'a\\': '1'})
|
ok(r'"a\\"=>"1"', {'a\\': '1'})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user