Revert "Revert nil error and adding deprecation message"
This reverts commit 452bee3ee8d68059fabd9b1c7a75661b14e3933e.
This commit is contained in:
parent
a705f6472c
commit
08074eb712
8
re.c
8
re.c
@ -3299,9 +3299,7 @@ rb_reg_match_m(int argc, VALUE *argv, VALUE re)
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NIL_P(str)) {
|
str = SYMBOL_P(str) ? rb_sym2str(str) : StringValue(str);
|
||||||
rb_warn("given argument is nil");
|
|
||||||
}
|
|
||||||
pos = reg_match_pos(re, &str, pos);
|
pos = reg_match_pos(re, &str, pos);
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
rb_backref_set(Qnil);
|
rb_backref_set(Qnil);
|
||||||
@ -3347,10 +3345,6 @@ rb_reg_match_p(VALUE re, VALUE str, long pos)
|
|||||||
const UChar *start, *end;
|
const UChar *start, *end;
|
||||||
int tmpreg;
|
int tmpreg;
|
||||||
|
|
||||||
if (NIL_P(str)) {
|
|
||||||
rb_warn("given argument is nil");
|
|
||||||
return Qfalse;
|
|
||||||
}
|
|
||||||
str = SYMBOL_P(str) ? rb_sym2str(str) : StringValue(str);
|
str = SYMBOL_P(str) ? rb_sym2str(str) : StringValue(str);
|
||||||
if (pos) {
|
if (pos) {
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
|
@ -91,7 +91,7 @@ describe "Regexp#match" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is ""..."3.0" do
|
ruby_version_is ""..."2.7" do
|
||||||
it "resets $~ if passed nil" do
|
it "resets $~ if passed nil" do
|
||||||
# set $~
|
# set $~
|
||||||
/./.match("a")
|
/./.match("a")
|
||||||
@ -102,13 +102,7 @@ describe "Regexp#match" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is "2.7"..."3.0" do
|
ruby_version_is "2.7" do
|
||||||
it "warns the deprecation when the given argument is nil" do
|
|
||||||
-> { /foo/.match(nil) }.should complain(/given argument is nil/)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ruby_version_is "3.0" do
|
|
||||||
it "raises TypeError when the given argument is nil" do
|
it "raises TypeError when the given argument is nil" do
|
||||||
-> { /foo/.match(nil) }.should raise_error(TypeError)
|
-> { /foo/.match(nil) }.should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
@ -147,19 +141,13 @@ describe "Regexp#match?" do
|
|||||||
/str/i.match?('string', 1).should be_false
|
/str/i.match?('string', 1).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is ""..."3.0" do
|
ruby_version_is ""..."2.7" do
|
||||||
it "returns false when given nil" do
|
it "returns false when given nil" do
|
||||||
/./.match?(nil).should be_false
|
/./.match?(nil).should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is "2.7"..."3.0" do
|
ruby_version_is "2.7" do
|
||||||
it "warns the deprecation" do
|
|
||||||
-> { /./.match?(nil) }.should complain(/given argument is nil/)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ruby_version_is "3.0" do
|
|
||||||
it "raises TypeError when given nil" do
|
it "raises TypeError when given nil" do
|
||||||
-> { /./.match?(nil) }.should raise_error(TypeError)
|
-> { /./.match?(nil) }.should raise_error(TypeError)
|
||||||
end
|
end
|
||||||
|
@ -539,7 +539,7 @@ class TestRegexp < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_match
|
def test_match
|
||||||
assert_nil(//.match(nil))
|
assert_raise(TypeError) { //.match(nil) }
|
||||||
assert_equal("abc", /.../.match(:abc)[0])
|
assert_equal("abc", /.../.match(:abc)[0])
|
||||||
assert_raise(TypeError) { /.../.match(Object.new)[0] }
|
assert_raise(TypeError) { /.../.match(Object.new)[0] }
|
||||||
assert_equal("bc", /../.match('abc', 1)[0])
|
assert_equal("bc", /../.match('abc', 1)[0])
|
||||||
@ -561,10 +561,10 @@ class TestRegexp < Test::Unit::TestCase
|
|||||||
/backref/ =~ 'backref'
|
/backref/ =~ 'backref'
|
||||||
# must match here, but not in a separate method, e.g., assert_send,
|
# must match here, but not in a separate method, e.g., assert_send,
|
||||||
# to check if $~ is affected or not.
|
# to check if $~ is affected or not.
|
||||||
assert_equal(false, //.match?(nil))
|
|
||||||
assert_equal(true, //.match?(""))
|
assert_equal(true, //.match?(""))
|
||||||
assert_equal(true, /.../.match?(:abc))
|
assert_equal(true, /.../.match?(:abc))
|
||||||
assert_raise(TypeError) { /.../.match?(Object.new) }
|
assert_raise(TypeError) { /.../.match?(Object.new) }
|
||||||
|
assert_raise(TypeError) { //.match?(nil) }
|
||||||
assert_equal(true, /b/.match?('abc'))
|
assert_equal(true, /b/.match?('abc'))
|
||||||
assert_equal(true, /b/.match?('abc', 1))
|
assert_equal(true, /b/.match?('abc', 1))
|
||||||
assert_equal(true, /../.match?('abc', 1))
|
assert_equal(true, /../.match?('abc', 1))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user