diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 705fc8135d..d7adcdc5d4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -64,27 +64,25 @@ module ActiveRecord end private + HSTORE_ESCAPE = { + ' ' => '\\ ', + '\\' => '\\\\', + '"' => '\\"', + '=' => '\\=', + } + HSTORE_ESCAPE_RE = Regexp.union(HSTORE_ESCAPE.keys) + HSTORE_UNESCAPE = HSTORE_ESCAPE.invert + HSTORE_UNESCAPE_RE = Regexp.union(HSTORE_UNESCAPE.keys) + def unescape_hstore(value) - escape_values = { - '\\ ' => ' ', - '\\\\' => '\\', - '\\"' => '"', - '\\=' => '=', - } - value.gsub(Regexp.union(escape_values.keys)) do |match| - escape_values[match] + value.gsub(HSTORE_UNESCAPE_RE) do |match| + HSTORE_UNESCAPE[match] end end def escape_hstore(value) - escape_values = { - ' ' => '\\ ', - '\\' => '\\\\', - '"' => '\\"', - '=' => '\\=', - } - value.gsub(Regexp.union(escape_values.keys)) do |match| - escape_values[match] + value.gsub(HSTORE_ESCAPE_RE) do |match| + HSTORE_ESCAPE[match] end end end |