diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 303f35cf74..88908cff45 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Removing trailing whitespace when matching columns in + `ActiveRecord::Sanitization.disallow_raw_sql!`. + + *Gannon McGibbon*, *Adrian Hirt* + * Expose a way for applications to set a `primary_abstract_class` Multiple database applications that use a primary abstract class that is not diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index 6e3ffe5fc6..df8027b6d0 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -137,7 +137,7 @@ module ActiveRecord def disallow_raw_sql!(args, permit: connection.column_name_matcher) # :nodoc: unexpected = nil args.each do |arg| - next if arg.is_a?(Symbol) || Arel.arel_node?(arg) || permit.match?(arg.to_s) + next if arg.is_a?(Symbol) || Arel.arel_node?(arg) || permit.match?(arg.to_s.strip) (unexpected ||= []) << arg end diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 29e04be9cc..25b29b0205 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -914,6 +914,11 @@ class CalculationsTest < ActiveRecord::TestCase Account.order(:id).pluck("id, credit_limit") end + def test_pluck_with_line_endings + assert_equal [[1, 50], [2, 50], [3, 50], [4, 60], [5, 55], [6, 53]], + Account.order(:id).pluck("id, credit_limit\n") + end + def test_pluck_with_multiple_columns_and_includes Company.create!(name: "test", contracts: [Contract.new(developer_id: 7)]) companies_and_developers = Company.order("companies.id").includes(:contracts).pluck(:name, :developer_id)