aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/string.c b/string.c
index 189cc1b751..d72d0352c7 100644
--- a/string.c
+++ b/string.c
@@ -2720,7 +2720,9 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
if (OBJ_TAINTED(val)) tainted = 1;
len = beg - offset; /* copy pre-match substr */
- rb_enc_str_buf_cat(dest, cp, len, str_enc);
+ if (len) {
+ rb_enc_str_buf_cat(dest, cp, len, str_enc);
+ }
rb_str_buf_append(dest, val);