Created
December 28, 2010 13:51
-
-
Save matthewd/757215 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 3b189997274ff067a43a7509b4a35a818d6c01d9 Mon Sep 17 00:00:00 2001 | |
| From: Matthew Draper <[email protected]> | |
| Date: Wed, 29 Dec 2010 00:14:57 +1030 | |
| Subject: [PATCH] Regexp literals raise a SyntaxError. | |
| --- | |
| kernel/common/regexp.rb | 6 ++++++ | |
| lib/compiler/ast/literals.rb | 2 +- | |
| spec/compiler/match2_spec.rb | 2 +- | |
| spec/compiler/match3_spec.rb | 2 +- | |
| spec/compiler/match_spec.rb | 2 +- | |
| spec/compiler/regex_spec.rb | 8 ++++---- | |
| spec/language/regexp_spec.rb | 2 +- | |
| 7 files changed, 15 insertions(+), 9 deletions(-) | |
| diff --git a/kernel/common/regexp.rb b/kernel/common/regexp.rb | |
| index 23519ab..61513e2 100644 | |
| --- a/kernel/common/regexp.rb | |
| +++ b/kernel/common/regexp.rb | |
| @@ -102,6 +102,12 @@ class Regexp | |
| alias_method :quote, :escape | |
| end | |
| + def self.new_literal(source, opts) | |
| + new(source, opts) | |
| + rescue RegexpError => ex | |
| + raise SyntaxError, ex.message, ex | |
| + end | |
| + | |
| def initialize_copy(other) | |
| initialize other.source, other.options, other.kcode | |
| end | |
| diff --git a/lib/compiler/ast/literals.rb b/lib/compiler/ast/literals.rb | |
| index c477cb4..19b0edf 100644 | |
| --- a/lib/compiler/ast/literals.rb | |
| +++ b/lib/compiler/ast/literals.rb | |
| @@ -299,7 +299,7 @@ module Rubinius | |
| g.find_const :Regexp | |
| g.push_literal @source | |
| g.push @options | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| g.set_literal idx | |
| lbl.set! | |
| end | |
| diff --git a/spec/compiler/match2_spec.rb b/spec/compiler/match2_spec.rb | |
| index 9753859..465a434 100644 | |
| --- a/spec/compiler/match2_spec.rb | |
| +++ b/spec/compiler/match2_spec.rb | |
| @@ -8,7 +8,7 @@ describe "A Match2 node" do | |
| g.find_const :Regexp | |
| g.push_literal "x" | |
| g.push 0 | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| end | |
| g.push_literal "blah" | |
| diff --git a/spec/compiler/match3_spec.rb b/spec/compiler/match3_spec.rb | |
| index 8b7d101..3b3dc5a 100644 | |
| --- a/spec/compiler/match3_spec.rb | |
| +++ b/spec/compiler/match3_spec.rb | |
| @@ -11,7 +11,7 @@ describe "A Match3 node" do | |
| g.find_const :Regexp | |
| g.push_literal "x" | |
| g.push 0 | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| end | |
| g.send :=~, 1 | |
| diff --git a/spec/compiler/match_spec.rb b/spec/compiler/match_spec.rb | |
| index 40e1b10..86a0627 100644 | |
| --- a/spec/compiler/match_spec.rb | |
| +++ b/spec/compiler/match_spec.rb | |
| @@ -13,7 +13,7 @@ describe "A Match node" do | |
| g.find_const :Regexp | |
| g.push_literal "x" | |
| g.push 0 | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| end | |
| f = g.new_label | |
| diff --git a/spec/compiler/regex_spec.rb b/spec/compiler/regex_spec.rb | |
| index ee9d8f3..425b5bf 100644 | |
| --- a/spec/compiler/regex_spec.rb | |
| +++ b/spec/compiler/regex_spec.rb | |
| @@ -11,7 +11,7 @@ describe "A Regex node" do | |
| g.find_const :Regexp | |
| g.push_literal "" | |
| g.push 1 | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| end | |
| g.send :split, 1, false | |
| @@ -25,7 +25,7 @@ describe "A Regex node" do | |
| g.find_const :Regexp | |
| g.push_literal "x" | |
| g.push 16 | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| end | |
| end | |
| end | |
| @@ -37,7 +37,7 @@ describe "A Regex node" do | |
| g.find_const :Regexp | |
| g.push_literal "x" | |
| g.push 0 | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| end | |
| end | |
| end | |
| @@ -49,7 +49,7 @@ describe "A Regex node" do | |
| g.find_const :Regexp | |
| g.push_literal "x" | |
| g.push 0 | |
| - g.send :new, 2 | |
| + g.send :new_literal, 2 | |
| end | |
| end | |
| end | |
| diff --git a/spec/language/regexp_spec.rb b/spec/language/regexp_spec.rb | |
| index 99ee7b8..b41c6ae 100644 | |
| --- a/spec/language/regexp_spec.rb | |
| +++ b/spec/language/regexp_spec.rb | |
| @@ -17,7 +17,7 @@ describe "Regexps with capture group modifers" do | |
| end | |
| it "doesn't allow numbered-backref/call" do | |
| - lambda{ /(foo)(?<name>bar)\1/ }.should raise_error(RegexpError) | |
| + lambda{ /(foo)(?<name>bar)\1/ }.should raise_error(SyntaxError) | |
| end | |
| end | |
| -- | |
| 1.7.2.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment