aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/string.c b/string.c
index 6e316426af..2b0c69c6fc 100644
--- a/string.c
+++ b/string.c
@@ -3893,9 +3893,14 @@ rb_pat_search(VALUE pat, VALUE str, long pos, int set_backref_str)
{
if (BUILTIN_TYPE(pat) == T_STRING) {
pos = rb_str_index(str, pat, pos);
- if (pos >= 0 && set_backref_str) {
- str = rb_str_new_frozen(str);
- rb_backref_set_string(str, pos, RSTRING_LEN(pat));
+ if (set_backref_str) {
+ if (pos >= 0) {
+ str = rb_str_new_frozen(str);
+ rb_backref_set_string(str, pos, RSTRING_LEN(pat));
+ }
+ else {
+ rb_backref_set(Qnil);
+ }
}
return pos;
}