Permalink
Browse files

Fix regex to strip quotations from hstore values

Previously regex did not strip quotation marks where hstore values were multi-line strings.
  • Loading branch information...
1 parent bad0b81 commit 2c9304891ef264409980abfac499f698876744d0 @jlxw jlxw committed with rafaelfranca Feb 5, 2013
@@ -30,8 +30,8 @@ def string_to_hstore(string)
nil
elsif String === string
Hash[string.scan(HstorePair).map { |k,v|
- v = v.upcase == 'NULL' ? nil : v.gsub(/^"(.*)"$/,'\1').gsub(/\\(.)/, '\1')
- k = k.gsub(/^"(.*)"$/,'\1').gsub(/\\(.)/, '\1')
+ v = v.upcase == 'NULL' ? nil : v.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
+ k = k.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
[k,v]
}]
else
@@ -189,6 +189,10 @@ def test_quoting_special_characters
assert_cycle('ca' => '', 'ac' => 'àc')
end
+ def test_multiline
+ assert_cycle("a\nb" => "c\nd")
+ end
+
private
def assert_cycle hash
# test creation

0 comments on commit 2c93048

Please sign in to comment.