Permalink
Browse files

Merge pull request #5973 from academia-edu/master

Always quote hstore keys and values
  • Loading branch information...
2 parents 2a97636 + 1a05e15 commit bc7309cde337bbd56326fd1f0b38e553f64b519e @tenderlove tenderlove committed Apr 25, 2012
@@ -88,9 +88,8 @@ def string_to_hstore(string)
def escape_hstore(value)
value.nil? ? 'NULL'
- : value =~ /[=\s,>]/ ? '"%s"' % value.gsub(/(["\\])/, '\\\\\1')
: value == "" ? '""'
- : value.to_s.gsub(/(["\\])/, '\\\\\1')
+ : '"%s"' % value.to_s.gsub(/(["\\])/, '\\\\\1')
end
end
# :startdoc:
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require "cases/helper"
require 'active_record/base'
require 'active_record/connection_adapters/postgresql_adapter'
@@ -134,13 +136,19 @@ def test_arrow
assert_cycle('a=>b' => 'bar', '1"foo' => '2')
end
+ def test_quoting_special_characters
+ assert_cycle('ca' => '', 'ac' => 'àc')
+ end
+
private
def assert_cycle hash
+ # test creation
x = Hstore.create!(:tags => hash)
x.reload
assert_equal(hash, x.tags)
- # make sure updates work
+ # test updating
+ x = Hstore.create!(:tags => {})
x.tags = hash
x.save!
x.reload

0 comments on commit bc7309c

Please sign in to comment.