mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
activerecord: Allow comment prefix in queries when preventing writes
This commit is contained in:
parent
ff7a88d456
commit
b94efe9f1b
2 changed files with 4 additions and 3 deletions
|
@ -76,6 +76,7 @@ module ActiveRecord
|
|||
include Savepoints
|
||||
|
||||
SIMPLE_INT = /\A\d+\z/
|
||||
COMMENT_REGEX = %r{/\*(?:[^\*]|\*[^/])*\*/}m
|
||||
|
||||
attr_accessor :pool
|
||||
attr_reader :visitor, :owner, :logger, :lock
|
||||
|
@ -102,8 +103,8 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def self.build_read_query_regexp(*parts) # :nodoc:
|
||||
parts = parts.map { |part| /\A[\(\s]*#{part}/i }
|
||||
Regexp.union(*parts)
|
||||
parts = parts.map { |part| /#{part}/i }
|
||||
/\A(?:[\(\s]|#{COMMENT_REGEX})*#{Regexp.union(*parts)}/
|
||||
end
|
||||
|
||||
def self.quoted_column_names # :nodoc:
|
||||
|
|
|
@ -221,7 +221,7 @@ class Mysql2AdapterTest < ActiveRecord::Mysql2TestCase
|
|||
@conn.execute("INSERT INTO `engines` (`car_id`) VALUES ('138853948594')")
|
||||
|
||||
@connection_handler.while_preventing_writes do
|
||||
assert_equal 1, @conn.execute("(\n( SELECT `engines`.* FROM `engines` WHERE `engines`.`car_id` = '138853948594' ) )").entries.count
|
||||
assert_equal 1, @conn.execute("/*action:index*/(\n( SELECT `engines`.* FROM `engines` WHERE `engines`.`car_id` = '138853948594' ) )").entries.count
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue