aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorKevin Deisz <kevin.deisz@gmail.com>2018-08-27 09:30:05 -0400
committerKevin Deisz <kevin.deisz@gmail.com>2018-08-27 09:51:46 -0400
commit7c9751d7fe3aec1e67004d1bb5e4a1702fcacafb (patch)
treef67885f8ceeee2b867a451afcab6a145425dcadb /activerecord/lib/active_record/attribute_methods.rb
parent0efecd913c07104e8fba82d5044c1ad824af68d5 (diff)
downloadrails-7c9751d7fe3aec1e67004d1bb5e4a1702fcacafb.tar.gz
rails-7c9751d7fe3aec1e67004d1bb5e4a1702fcacafb.tar.bz2
rails-7c9751d7fe3aec1e67004d1bb5e4a1702fcacafb.zip
Permit list usage cleanup and clearer documentation
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 2e68bdd741..1d18119c66 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -167,12 +167,14 @@ module ActiveRecord
end
end
- # Regexp permitted list. Matches the following:
+ # Regexp for column names (with or without a table name prefix). Matches
+ # the following:
# "#{table_name}.#{column_name}"
# "#{column_name}"
- COLUMN_NAME_PERMIT_LIST = /\A(?:\w+\.)?\w+\z/i
+ COLUMN_NAME = /\A(?:\w+\.)?\w+\z/i
- # Regexp permitted list. Matches the following:
+ # Regexp for column names with order (with or without a table name
+ # prefix, with or without various order modifiers). Matches the following:
# "#{table_name}.#{column_name}"
# "#{table_name}.#{column_name} #{direction}"
# "#{table_name}.#{column_name} #{direction} NULLS FIRST"
@@ -181,7 +183,7 @@ module ActiveRecord
# "#{column_name} #{direction}"
# "#{column_name} #{direction} NULLS FIRST"
# "#{column_name} NULLS LAST"
- COLUMN_NAME_ORDER_PERMIT_LIST = /
+ COLUMN_NAME_WITH_ORDER = /
\A
(?:\w+\.)?
\w+
@@ -190,12 +192,12 @@ module ActiveRecord
\z
/ix
- def enforce_raw_sql_permit_list(args, permit_list: COLUMN_NAME_PERMIT_LIST) # :nodoc:
+ def disallow_raw_sql!(args, permit: COLUMN_NAME) # :nodoc:
unexpected = args.reject do |arg|
arg.kind_of?(Arel::Node) ||
arg.is_a?(Arel::Nodes::SqlLiteral) ||
arg.is_a?(Arel::Attributes::Attribute) ||
- arg.to_s.split(/\s*,\s*/).all? { |part| permit_list.match?(part) }
+ arg.to_s.split(/\s*,\s*/).all? { |part| permit.match?(part) }
end
return if unexpected.none?