Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activerecord: Allow comment prefix in queries when preventing writes #37184

Merged
merged 1 commit into from Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -76,6 +76,7 @@ class AbstractAdapter
include Savepoints

SIMPLE_INT = /\A\d+\z/
COMMENT_REGEX = %r{/\*(?:[^\*]|\*[^/])*\*/}m

attr_accessor :pool
attr_reader :visitor, :owner, :logger, :lock
Expand All @@ -102,8 +103,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:
Expand Down
Expand Up @@ -221,7 +221,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

Expand Down