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
TypeError Regexp#match?(nil) in Ruby Head #37504
TypeError Regexp#match?(nil) in Ruby Head #37504
Conversation
What would the perf/memory impact be of using |
I'll have a look. |
4a4c9f1
to
49af919
Compare
@@ -346,7 +346,7 @@ def check_part(name, part, path_params, hash) | |||
end | |||
|
|||
def split_to(to) | |||
if /#/.match?(to) | |||
if !to.nil? && /#/.match?(to) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simplify to if to && /#/.match?(to)
here and other places.
If to
was false
, it would already raise a TypeError in <=2.6.
@@ -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.nil? && %r{\A/}.match?(controller) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if controller && controller.start_with?('/')
would be more readable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using start_with?
here should have been enforced by RuboCop in #32695, but wasn't due to a bug (rubocop/rubocop#7464).
In any case, I think this patch should only contain changes required for compatibility with ruby/ruby#1506, no matter how tempting adjacent refactorings may be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it's probably safer to just directly fix the compatibility with ruby-head in this PR.
49af919
to
a3ff6a6
Compare
@@ -280,7 +280,11 @@ def layout(layout, conditions = {}) | |||
def _write_layout_method # :nodoc: | |||
silence_redefinition_of_method(:_layout) | |||
|
|||
prefixes = /\blayouts/.match?(_implied_layout_name) ? [] : ["layouts"] | |||
if _implied_layout_name.nil? | |||
["layouts"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not assigned to prefixes
.
It seems better to keep the condition together:
prefixes = if _implied_layout_name && /\blayouts/.match?(_implied_layout_name)
[]
else
["layouts"]
end
@@ -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.nil? && !default_value && %r{\w+\(.*\)|\(.*\)::\w+|CURRENT_DATE|CURRENT_TIMESTAMP}.match?(default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this to keep closer to the original code and avoid double negation:
!default.nil? && !default_value && %r{\w+\(.*\)|\(.*\)::\w+|CURRENT_DATE|CURRENT_TIMESTAMP}.match?(default) | |
!default_value && default && %r{\w+\(.*\)|\(.*\)::\w+|CURRENT_DATE|CURRENT_TIMESTAMP}.match?(default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
c328207
to
32e4e0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this is a backward incompatible change in Ruby and should be fixed there.
Discussion on the Ruby tracker: https://bugs.ruby-lang.org/issues/13083 It still seems unintentional to me to pass |
I'm fine with changing the code to avoid deprecation but I think we can avoid that this change break apps. |
There's one more rails/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb Line 165 in 9bfb73a
It currently causes the Active Record test suite to fail when run with the mysql2 adapter:
|
Aa of ruby/ruby@2a22a6b calling `Regexp#match?(nil)` raises an exception. [utilum, eregon, eugeneius]
32e4e0c
to
2ca6830
Compare
ruby/ruby#2637 was merged, so |
TypeError Regexp#match?(nil) in Ruby Head
…of_nil" This reverts commit 4e10538, reversing changes made to 62b4383. The change in Ruby that made those changes required was reverted in https://bugs.ruby-lang.org/projects/ruby-trunk/repository/git/revisions/8852fa876039ed177fd5e867f36177d8a9ff411c
…of_nil" This reverts commit a077f94. That commit in Ruby that required those changes were reverted in https://bugs.ruby-lang.org/projects/ruby-trunk/repository/git/revisions/8852fa876039ed177fd5e867f36177d8a9ff411c
Aa of ruby/ruby@2a22a6b calling
Regexp#match?(nil)
raises an exception.This fixes instances instances raised by the test suite.