1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix regex to strip quotations from hstore values

Previously regex did not strip quotation marks where hstore values were multi-line strings.
This commit is contained in:
jlxw 2013-02-05 16:49:33 +08:00 committed by Rafael Mendonça França
parent bad0b81a07
commit 2c9304891e
2 changed files with 6 additions and 2 deletions

View file

@ -30,8 +30,8 @@ module ActiveRecord
nil nil
elsif String === string elsif String === string
Hash[string.scan(HstorePair).map { |k,v| Hash[string.scan(HstorePair).map { |k,v|
v = v.upcase == 'NULL' ? nil : v.gsub(/^"(.*)"$/,'\1').gsub(/\\(.)/, '\1') v = v.upcase == 'NULL' ? nil : v.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
k = k.gsub(/^"(.*)"$/,'\1').gsub(/\\(.)/, '\1') k = k.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
[k,v] [k,v]
}] }]
else else

View file

@ -189,6 +189,10 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
assert_cycle('ca' => 'cà', 'ac' => 'àc') assert_cycle('ca' => 'cà', 'ac' => 'àc')
end end
def test_multiline
assert_cycle("a\nb" => "c\nd")
end
private private
def assert_cycle hash def assert_cycle hash
# test creation # test creation