Fix Performance/StringInclude that RuboCop can't

This replaces two instances of /html/.match?(<string>) with the more
performant <string>.include?("html").

Performance/StringInclude was enabled in 3158bbb, however RuboCop does
not flag these two because it is unable to determine that the variable
passed to #match? is a string. In both these cases we know that the
variable must be a string (Mime::Type must be initialized with a string,
and Content-Type must be a string if present per Rack SPEC)

These were found by `rg '/\[\w ]+/\.match\?'`, and while this search
returns other entries they are either comments or in test files.
This commit is contained in:
Hartley McGuire 2023-01-06 15:37:56 -05:00
parent ae569eaef8
commit 583ce94c22
No known key found for this signature in database
GPG Key ID: E823FC1403858A82
2 changed files with 2 additions and 2 deletions

View File

@ -293,7 +293,7 @@ module Mime
end
def html?
(symbol == :html) || /html/.match?(@string)
(symbol == :html) || @string.include?("html")
end
def all?; false; end

View File

@ -55,7 +55,7 @@ module ActionDispatch # :nodoc:
private
def html_response?(headers)
if content_type = headers[CONTENT_TYPE]
/html/.match?(content_type)
content_type.include?("html")
end
end