diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-09-19 21:51:53 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-11-19 12:05:46 +0900 |
| commit | ff08856fe314faa4d16b4502c0960a3475387846 (patch) | |
| tree | 5e5bd17dc3d05a9be4c02fe80d3ecfea0ff68269 /mrblib | |
| parent | afca99a40b8a3415b3a9a0e8fc41c93ddcbb11d8 (diff) | |
| download | mruby-ff08856fe314faa4d16b4502c0960a3475387846.tar.gz mruby-ff08856fe314faa4d16b4502c0960a3475387846.zip | |
Remove implicit conversion using `to_str` method; fix #3854
We have added internal convenience method `__to_str` which
does string type check.
The issue #3854 was fixed but fundamental flaw of lack of stack
depth check along with fibers still remains. Use `MRB_GC_FIXED_ARENA`
for workaround.
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/string.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb index 07b80b340..397603e9d 100644 --- a/mrblib/string.rb +++ b/mrblib/string.rb @@ -12,7 +12,7 @@ class String def each_line(rs = "\n", &block) return to_enum(:each_line, rs, &block) unless block return block.call(self) if rs.nil? - rs = rs.to_str + rs = rs.__to_str offset = 0 rs_len = rs.length this = dup @@ -67,7 +67,7 @@ class String block = nil end if !replace.nil? || !block - replace = replace.to_str + replace = replace.__to_str end offset = 0 result = [] @@ -129,12 +129,12 @@ class String end pattern, replace = *args - pattern = pattern.to_str + pattern = pattern.__to_str if args.length == 2 && block block = nil end unless block - replace = replace.to_str + replace = replace.__to_str end result = [] this = dup @@ -245,14 +245,13 @@ class String ## # ISO 15.2.10.5.3 def =~(re) - raise TypeError, "type mismatch: String given" if re.respond_to? :to_str re =~ self end ## # ISO 15.2.10.5.27 def match(re, &block) - if re.respond_to? :to_str + if String === re if Object.const_defined?(:Regexp) r = Regexp.new(re) r.match(self, &block) |
