未验证 提交 a077f94f 编写于 作者: R Rafael França 提交者: Rafael Mendonça França

Merge pull request #37504 from utilum/no_implicit_conversion_of_nil

TypeError Regexp#match?(nil) in Ruby Head
上级 bd8a709a
......@@ -282,7 +282,7 @@ def marked_for_same_origin_verification? # :doc:
# Check for cross-origin JavaScript responses.
def non_xhr_javascript_response? # :doc:
%r(\A(?:text|application)/javascript).match?(media_type) && !request.xhr?
media_type && %r(\A(?:text|application)/javascript).match?(media_type) && !request.xhr?
end
AUTHENTICITY_TOKEN_LENGTH = 32
......
......@@ -231,7 +231,7 @@ def unregister(symbol)
class InvalidMimeType < StandardError; end
def initialize(string, symbol = nil, synonyms = [])
unless MIME_REGEXP.match?(string)
if string.nil? || ! MIME_REGEXP.match?(string)
raise InvalidMimeType, "#{string.inspect} is not a valid MIME type"
end
@symbol, @synonyms = symbol, synonyms
......
......@@ -264,7 +264,8 @@ def content_length
# (case-insensitive), which may need to be manually added depending on the
# choice of JavaScript libraries and frameworks.
def xml_http_request?
get_header("HTTP_X_REQUESTED_WITH") =~ /XMLHttpRequest/i
header = get_header("HTTP_X_REQUESTED_WITH")
header && /XMLHttpRequest/i.match?(header)
end
alias :xhr? :xml_http_request?
......
......@@ -152,7 +152,7 @@ def missing_keys(route, parts)
missing_keys << key
end
else
unless /\A#{tests[key]}\Z/ === parts[key]
if parts[key].nil? || !/\A#{tests[key]}\Z/.match?(parts[key])
missing_keys ||= []
missing_keys << key
end
......
......@@ -341,7 +341,7 @@ def check_part(name, part, path_params, hash)
end
def split_to(to)
if /#/.match?(to)
if to && /#/.match?(to)
to.split("#")
else
[]
......@@ -350,7 +350,7 @@ def split_to(to)
def add_controller_module(controller, modyoule)
if modyoule && !controller.is_a?(Regexp)
if %r{\A/}.match?(controller)
if controller && controller.start_with?("/")
controller[1..-1]
else
[modyoule, controller].compact.join("/")
......
......@@ -281,7 +281,11 @@ def layout(layout, conditions = {})
def _write_layout_method # :nodoc:
silence_redefinition_of_method(:_layout)
prefixes = /\blayouts/.match?(_implied_layout_name) ? [] : ["layouts"]
prefixes = if _implied_layout_name && /\blayouts/.match?(_implied_layout_name)
[]
else
["layouts"]
end
default_behavior = "lookup_context.find_all('#{_implied_layout_name}', #{prefixes.inspect}, false, [], { formats: formats }).first || super"
name_clause = if name
default_behavior
......
......@@ -2,7 +2,8 @@
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "is not an email") unless
/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.match?(value)
if value.nil? || ! /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.match?(value)
record.errors[attribute] << (options[:message] || "is not an email")
end
end
end
......@@ -85,7 +85,9 @@ class AbstractAdapter
set_callback :checkin, :after, :enable_lazy_transactions!
def self.type_cast_config_to_integer(config)
if config.is_a?(Integer)
if config.nil?
config
elsif config.is_a?(Integer)
config
elsif SIMPLE_INT.match?(config)
config.to_i
......
......@@ -162,7 +162,7 @@ def new_column_from_field(table_name, field)
type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
default, default_function = field[:Default], nil
if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(default)
if type_metadata.type == :datetime && default && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(default)
default, default_function = nil, default
elsif type_metadata.extra == "DEFAULT_GENERATED"
default = +"(#{default})" unless default.start_with?("(")
......
......@@ -617,7 +617,7 @@ def extract_default_function(default_value, default)
end
def has_default_function?(default_value, default)
!default_value && %r{\w+\(.*\)|\(.*\)::\w+|CURRENT_DATE|CURRENT_TIMESTAMP}.match?(default)
!default_value && default && %r{\w+\(.*\)|\(.*\)::\w+|CURRENT_DATE|CURRENT_TIMESTAMP}.match?(default)
end
def load_additional_types(oids = nil)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册