From 389abf1b3b9e65b5944fa3616bea93259b137a92 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 8 Jan 2008 06:04:26 +0000 Subject: [PATCH] * string.c (str_gsub): avoid appending empty pre-match substr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ string.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 67c3213b9a..bdffe38aee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Jan 8 15:03:10 2008 Tanaka Akira + + * string.c (str_gsub): avoid appending empty pre-match substr. + Tue Jan 8 13:05:57 2008 Nobuyoshi Nakada * compile.c (iseq_build_from_ary), iseq.c (iseq_load): fix for format change. 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);