提交 290e4859 编写于 作者: R Rafael França 提交者: Eugene Kenny

Merge pull request #37184 from dylanahsmith/read-query-comment-prefix

activerecord: Allow comment prefix in queries when preventing writes
上级 370188ae
......@@ -77,6 +77,7 @@ class AbstractAdapter
include Savepoints
SIMPLE_INT = /\A\d+\z/
COMMENT_REGEX = %r{/\*(?:[^\*]|\*[^/])*\*/}m
attr_accessor :pool
attr_reader :visitor, :owner, :logger, :lock
......@@ -103,8 +104,8 @@ def self.type_cast_config_to_boolean(config)
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:
......
......@@ -237,7 +237,7 @@ def test_doesnt_error_when_a_read_query_with_leading_chars_is_called_while_preve
@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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册