aboutsummaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
Diffstat (limited to 're.c')
-rw-r--r--re.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/re.c b/re.c
index 106cf593ac..1ceb6eaaf1 100644
--- a/re.c
+++ b/re.c
@@ -1375,7 +1375,7 @@ rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, int reverse)
/* returns byte offset */
long
-rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
+rb_reg_search0(VALUE re, VALUE str, long pos, int reverse, int set_backref_str)
{
long result;
VALUE match;
@@ -1450,17 +1450,26 @@ rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
FL_UNSET(match, FL_TAINT);
}
- RMATCH(match)->str = rb_str_new4(str);
+ if (set_backref_str) {
+ RMATCH(match)->str = rb_str_new4(str);
+ OBJ_INFECT(match, str);
+ }
+
RMATCH(match)->regexp = re;
RMATCH(match)->rmatch->char_offset_updated = 0;
rb_backref_set(match);
OBJ_INFECT(match, re);
- OBJ_INFECT(match, str);
return result;
}
+long
+rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
+{
+ return rb_reg_search0(re, str, pos, reverse, 1);
+}
+
VALUE
rb_reg_nth_defined(int nth, VALUE match)
{