Skip to content

Commit b83ba83

Browse files
committed
Fix Regexp.new - show warning "flags ignored" when passed regexp and options
1 parent 7102d5c commit b83ba83

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

spec/ruby/core/regexp/new_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
describe "Regexp.new given a Regexp" do
1313
it_behaves_like :regexp_new_regexp, :new
14-
it_behaves_like :regexp_new_string_binary, :compile
14+
it_behaves_like :regexp_new_string_binary, :new
1515
end
1616

1717
describe "Regexp.new given a non-String/Regexp" do
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
fails:Regexp.compile given a String ignores the third argument if it is 'e' or 'euc' (case-insensitive)
22
fails:Regexp.compile given a String ignores the third argument if it is 's' or 'sjis' (case-insensitive)
33
fails:Regexp.compile given a String ignores the third argument if it is 'u' or 'utf8' (case-insensitive)
4-
fails:Regexp.compile given a Regexp does not honour options given as additional arguments
54
fails(immutable regexp):Regexp.compile works by default for subclasses with overridden #initialize

spec/tags/core/regexp/new_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
fails:Regexp.new given a String ignores the third argument if it is 'e' or 'euc' (case-insensitive)
22
fails:Regexp.new given a String ignores the third argument if it is 's' or 'sjis' (case-insensitive)
33
fails:Regexp.new given a String ignores the third argument if it is 'u' or 'utf8' (case-insensitive)
4-
fails:Regexp.new given a Regexp does not honour options given as additional arguments
54
fails(immutable regexp):Regexp.new works by default for subclasses with overridden #initialize

src/main/ruby/truffleruby/core/regexp.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ def self.union(*patterns)
130130
end
131131
Truffle::Graal.always_split(method(:union))
132132

133-
def self.new(pattern, opts=nil, lang=nil)
133+
def self.new(pattern, opts=undefined, lang=nil)
134134
if Primitive.object_kind_of?(pattern, Regexp)
135+
warn 'flags ignored' unless Primitive.undefined?(opts)
135136
opts = pattern.options
136137
pattern = pattern.source
137138
elsif Primitive.object_kind_of?(pattern, String)
@@ -141,7 +142,7 @@ def self.new(pattern, opts=nil, lang=nil)
141142

142143
if Primitive.object_kind_of?(opts, Integer)
143144
opts = opts & (OPTION_MASK | KCODE_MASK) if opts > 0
144-
elsif opts
145+
elsif !Primitive.undefined?(opts) && opts
145146
opts = IGNORECASE
146147
else
147148
opts = 0

0 commit comments

Comments
 (0)