summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-01-14 09:33:41 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-01-14 09:33:41 +0900
commit16884b87af3725c0c262b208855fd71183ff5604 (patch)
tree016ccc432abadab079e0d95d871bcd1267ab606f
parentd405eb554181910baf8bafa8bbdc7db55feb182c (diff)
parentbcceeba09b38eb8217f85aa5c11afac9eb9b888e (diff)
downloadmruby-16884b87af3725c0c262b208855fd71183ff5604.tar.gz
mruby-16884b87af3725c0c262b208855fd71183ff5604.zip
Merge pull request #2702 from takahashim/fix-string-match
fix infinite loop in String#match(arg) when arg is String
-rw-r--r--mrblib/string.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb
index 322cd0788..66a668e11 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -146,7 +146,16 @@ class String
##
# ISO 15.2.10.5.27
def match(re, &block)
- re.match(self, &block)
+ if re.respond_to? :to_str
+ if Object.const_defined?(:Regexp)
+ r = Regexp.new(re)
+ r.match(self, &block)
+ else
+ raise NotImplementedError, "String#match needs Regexp class"
+ end
+ else
+ re.match(self, &block)
+ end
end
end