Skip to content

Commit

Permalink
Merge pull request #37184 from dylanahsmith/read-query-comment-prefix
Browse files Browse the repository at this point in the history
activerecord: Allow comment prefix in queries when preventing writes
  • Loading branch information
rafaelfranca authored and eugeneius committed Apr 13, 2020
1 parent 370188a commit 290e485
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 290e485

Please sign in to comment.