Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2084,10 +2084,23 @@ def environment(env = File.basename($0, '.*'))
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

#
Expand Down
3 changes: 3 additions & 0 deletions test/optparse/test_optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def test_regexp
assert_equal(/foo/i, @reopt)
assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/n")})
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

def test_into
Expand Down