From bdf9c751ad3b6f3166afdc0e6332955f52dc51f3 Mon Sep 17 00:00:00 2001 From: Maxime Lapointe Date: Tue, 27 Nov 2018 22:20:57 -0500 Subject: [PATCH] truffle workaround #1484 https://github.com/oracle/truffleruby/issues/1484 --- core_gem/lib/deep_cover/tools/scan_match_datas.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core_gem/lib/deep_cover/tools/scan_match_datas.rb b/core_gem/lib/deep_cover/tools/scan_match_datas.rb index 76da0ea9..aaf703a3 100644 --- a/core_gem/lib/deep_cover/tools/scan_match_datas.rb +++ b/core_gem/lib/deep_cover/tools/scan_match_datas.rb @@ -4,7 +4,16 @@ module DeepCover module Tools::ScanMatchDatas # Like String#scan, but return the MatchData object instead def scan_match_datas(source, matcher) - source.to_enum(:scan, matcher).map { Regexp.last_match } + # This has wrong behavior in truffleruby + # source.to_enum(:scan, matcher).map { Regexp.last_match } + # This is the fool-proof way of doing it. Maybe some checks for perf should be done + start_at = 0 + matches = [] + while (match = source.match(matcher, start_at)) + matches.push(match) + start_at = match.end(0) + end + matches end end end