[ruby/optparse] The encoding argument of Regexp.new has been ignored since 1.9

https://github.com/ruby/optparse/commit/766f567405
This commit is contained in:
Nobuyoshi Nakada 2022-12-21 14:07:54 +09:00
parent afd46429fc
commit 502ca37dde
2 changed files with 19 additions and 3 deletions

View File

@ -2084,10 +2084,23 @@ XXX
f |= Regexp::IGNORECASE if /i/ =~ o f |= Regexp::IGNORECASE if /i/ =~ o
f |= Regexp::MULTILINE if /m/ =~ o f |= Regexp::MULTILINE if /m/ =~ o
f |= Regexp::EXTENDED if /x/ =~ o f |= Regexp::EXTENDED if /x/ =~ o
k = o.delete("imx") case o = o.delete("imx")
k = nil if k.empty? when ""
when "u"
s = s.encode(Encoding::UTF_8)
when "e"
s = s.encode(Encoding::EUC_JP)
when "s"
s = s.encode(Encoding::SJIS)
when "n"
f |= Regexp::NOENCODING
else
raise OptionParser::InvalidArgument, "unknown regexp option - #{o}"
end
else
s ||= all
end end
Regexp.new(s || all, f, k) Regexp.new(s, f)
end end
# #

View File

@ -63,6 +63,9 @@ class TestOptionParser < Test::Unit::TestCase
assert_equal(/foo/i, @reopt) assert_equal(/foo/i, @reopt)
assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/n")}) assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/n")})
assert_equal(/foo/n, @reopt) assert_equal(/foo/n, @reopt)
assert_equal(%w"", no_error {@opt.parse!(%W"--regexp=/\u{3042}/s")})
assert_equal(Encoding::Windows_31J, @reopt.encoding)
assert_equal("\x82\xa0".force_encoding(Encoding::Windows_31J), @reopt.source)
end end
def test_into def test_into