Skip to content

Commit

Permalink
Merge pull request #3408 from rubinius/regex-new-2959
Browse files Browse the repository at this point in the history
Regex new 2959
  • Loading branch information
jemc committed May 24, 2015
2 parents 73e862e + a60dfb3 commit ffa628e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kernel/common/regexp.rb
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/ruby/core/regexp/new_spec.rb
Expand Up @@ -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.