summaryrefslogtreecommitdiff
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-21 14:07:54 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-21 14:09:12 +0900
commit502ca37dde288d20fed6e6ea34f4ab3299de7777 (patch)
treecad3f61822ef1b31e72e6d83b6885c8f32671dfc /lib/optparse.rb
parentafd46429fcdb83aa9fa7c193ede40bff3f3ff151 (diff)
[ruby/optparse] The encoding argument of `Regexp.new` has been ignored since 1.9
https://github.com/ruby/optparse/commit/766f567405
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r--lib/optparse.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index dc2b8a060f..b9126465e0 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -2084,10 +2084,23 @@ XXX
f |= Regexp::IGNORECASE if /i/ =~ o
f |= Regexp::MULTILINE if /m/ =~ o
f |= Regexp::EXTENDED if /x/ =~ o
- k = o.delete("imx")
- k = nil if k.empty?
+ case o = o.delete("imx")
+ 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
- Regexp.new(s || all, f, k)
+ Regexp.new(s, f)
end
#