diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-06-09 14:03:31 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-06-09 14:14:10 +0900 |
commit | 1340498d2102423665cc5cfe7be7cdba32c72928 (patch) | |
tree | 9067d11ca44f28919e55918e1fb5ef48f13eca0f /activerecord/lib/active_record/connection_adapters/postgresql | |
parent | 3567fa53f7dada3f5c66f4e72775f8bfa9f38f80 (diff) | |
download | rails-1340498d2102423665cc5cfe7be7cdba32c72928.tar.gz rails-1340498d2102423665cc5cfe7be7cdba32c72928.tar.bz2 rails-1340498d2102423665cc5cfe7be7cdba32c72928.zip |
Refactor `disallow_raw_sql!` to avoid `split(/\s*,\s*/)` to order args
`split(/\s*,\s*/)` to order args and then `permit.match?` one by one is
much slower than `permit.match?` once.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 0ebed21717..095429dd89 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -86,15 +86,23 @@ module ActiveRecord COLUMN_NAME_WITH_ORDER end - COLUMN_NAME = /\A(?:("?)\w+\k<1>\.)?("?)\w+\k<2>(?:::\w+)?\z/i + COLUMN_NAME = / + \A + ( + (?:\w+\.|"\w+"\.)?(?:\w+|"\w+")(?:::\w+)? + ) + (?:\s*,\s*\g<1>)* + \z + /ix COLUMN_NAME_WITH_ORDER = / \A - (?:("?)\w+\k<1>\.)? - ("?)\w+\k<2> - (?:::\w+)? - (?:\s+ASC|\s+DESC)? - (?:\s+NULLS\s+(?:FIRST|LAST))? + ( + (?:\w+\.|"\w+"\.)?(?:\w+|"\w+")(?:::\w+)? + (?:\s+ASC|\s+DESC)? + (?:\s+NULLS\s+(?:FIRST|LAST))? + ) + (?:\s*,\s*\g<1>)* \z /ix |