From 50091c990d268285097b2be5ce5331317227ba0c Mon Sep 17 00:00:00 2001 From: kosako Date: Thu, 23 Mar 2006 12:43:51 +0000 Subject: [PATCH] prohibit number backref in replaced string for named pattern git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ re.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fd8c09e50..db257eae9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Mar 23 21:40:47 2006 K.Kosako + + * re.c (rb_reg_regsub): prohibit \1, \2 ...\9 in replaced string + for named regex pattern. + Thu Mar 23 21:06:23 2006 K.Kosako * oniguruma.h: Version 4.0.2 diff --git a/re.c b/re.c index e2b27bdbd6..29a84f3c5c 100644 --- a/re.c +++ b/re.c @@ -2055,9 +2055,14 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp) uc = (unsigned char)*s++; p = s; switch (uc) { - case '0': case '1': case '2': case '3': case '4': + case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - no = uc - '0'; + if (onig_noname_group_capture_is_active(RREGEXP(regexp)->ptr)) { + no = uc - '0'; + } + else { + continue; + } break; case 'k': @@ -2083,6 +2088,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp) rb_str_buf_cat(val, s-2, 2); continue; + case '0': case '&': no = 0; break;