Skip to content

Commit

Permalink
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kernel/common/regexp.rb
Original file line number Diff line number Diff line change
@@ -128,6 +128,8 @@ def initialize(pattern, opts=nil, lang=nil)
if pattern.kind_of?(Regexp)
opts = pattern.options
pattern = pattern.source
elsif pattern.kind_of?(Fixnum) or pattern.kind_of?(Float)
raise TypeError, "can't convert Fixnum into String"
elsif opts.kind_of?(Fixnum)
opts = opts & (OPTION_MASK | KCODE_MASK) if opts > 0
elsif opts
12 changes: 12 additions & 0 deletions spec/ruby/core/regexp/new_spec.rb
Original file line number Diff line number Diff line change
@@ -16,3 +16,15 @@
it_behaves_like :regexp_new_regexp_ascii, :new
it_behaves_like :regexp_new_regexp_ascii_8bit, :new
end

describe "Regexp.new given a Fixnum" do
it "raises a TypeError" do
lambda { Regexp.new(1) }.should raise_error(TypeError)
end
end

describe "Regexp.new given a Float" do
it "raises a TypeError" do
lambda { Regexp.new(1.0) }.should raise_error(TypeError)
end
end

0 comments on commit ffa628e

Please sign in to comment.