Skip to content

Commit

Permalink
TypeError Regexp#match?(nil) in Ruby Head
Browse files Browse the repository at this point in the history
Aa of ruby/ruby@2a22a6b calling
`Regexp#match?(nil)` raises an exception.

[utilum, eregon, eugeneius]
  • Loading branch information
utilum committed Nov 3, 2019
1 parent 98754de commit 2ca6830
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 11 deletions.
Expand Up @@ -280,7 +280,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
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/mime_type.rb
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -265,7 +265,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?
/XMLHttpRequest/i.match?(get_header("HTTP_X_REQUESTED_WITH"))
header = get_header("HTTP_X_REQUESTED_WITH")
header && /XMLHttpRequest/i.match?(header)
end
alias :xhr? :xml_http_request?

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/journey/formatter.rb
Expand Up @@ -151,7 +151,7 @@ def missing_keys(route, parts)
missing_keys << key
end
else
unless /\A#{tests[key]}\Z/.match?(parts[key])
if parts[key].nil? || !/\A#{tests[key]}\Z/.match?(parts[key])
missing_keys ||= []
missing_keys << key
end
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -346,7 +346,7 @@ def check_part(name, part, path_params, hash)
end

def split_to(to)
if /#/.match?(to)
if to && /#/.match?(to)
to.split("#")
else
[]
Expand All @@ -355,7 +355,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("/")
Expand Down
7 changes: 6 additions & 1 deletion actionview/lib/action_view/layouts.rb
Expand Up @@ -280,7 +280,12 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion activemodel/test/validators/email_validator.rb
Expand Up @@ -2,7 +2,7 @@

class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
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.add(attribute, message: options[:message] || "is not an email")
end
end
Expand Down
Expand Up @@ -47,7 +47,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
Expand Down
Expand Up @@ -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?("(")
Expand Down
Expand Up @@ -620,7 +620,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)
Expand Down

0 comments on commit 2ca6830

Please sign in to comment.