From 2068d300917ed95a82e7377ee77b397fc4084a61 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 20 Sep 2012 01:43:36 -0300 Subject: Freeze columns just before using them as hash keys --- activerecord/lib/active_record/result.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb index 5011a0d75d..8905137142 100644 --- a/activerecord/lib/active_record/result.rb +++ b/activerecord/lib/active_record/result.rb @@ -11,7 +11,7 @@ module ActiveRecord attr_reader :columns, :rows, :column_types def initialize(columns, rows, column_types = {}) - @columns = columns.map{|c| c.freeze} + @columns = columns @rows = rows @hash_rows = nil @column_types = column_types @@ -54,7 +54,10 @@ module ActiveRecord private def hash_rows @hash_rows ||= @rows.map { |row| - Hash[@columns.zip(row)] + # We freeze the strings to prevent them getting duped when + # used as keys in ActiveRecord::Model's @attributes hash + columns = @columns.map { |c| c.freeze } + Hash[columns.zip(row)] } end end -- cgit v1.2.3