mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) 42251,46345,46346: [Backport #9903]
* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable characters. * sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable characters. * re.c (match_aref, rb_reg_regsub): consider encoding of captured names, encoding-incompatible should not match. [ruby-dev:48278] [Bug #9903] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b10c3b6d51
commit
d910ce1f90
7 changed files with 57 additions and 19 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Wed Sep 3 12:24:39 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* re.c (match_aref, rb_reg_regsub): consider encoding of captured
|
||||
names, encoding-incompatible should not match.
|
||||
[ruby-dev:48278] [Bug #9903]
|
||||
|
||||
Wed Sep 3 12:24:39 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
|
||||
characters.
|
||||
|
||||
Wed Sep 3 12:24:39 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
|
||||
characters.
|
||||
|
||||
Sun Aug 31 16:59:45 2014 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm_eval.c (rb_catch_protect): fix same problem of [Bug #9961].
|
||||
|
|
|
@ -106,4 +106,5 @@ Init_printf(void)
|
|||
rb_define_singleton_method(m, "s", printf_test_s, 1);
|
||||
rb_define_singleton_method(m, "v", printf_test_v, 1);
|
||||
rb_define_singleton_method(m, "call", printf_test_call, -1);
|
||||
rb_define_singleton_method(m, "q", printf_test_q, 1);
|
||||
}
|
||||
|
|
34
re.c
34
re.c
|
@ -1665,20 +1665,16 @@ match_captures(VALUE match)
|
|||
static int
|
||||
name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
|
||||
{
|
||||
int num;
|
||||
|
||||
num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
|
||||
return onig_name_to_backref_number(RREGEXP(regexp)->ptr,
|
||||
(const unsigned char* )name, (const unsigned char* )name_end, regs);
|
||||
if (num >= 1) {
|
||||
return num;
|
||||
}
|
||||
else {
|
||||
VALUE s = rb_str_new(name, (long )(name_end - name));
|
||||
rb_raise(rb_eIndexError, "undefined group name reference: %s",
|
||||
StringValuePtr(s));
|
||||
}
|
||||
}
|
||||
|
||||
UNREACHABLE;
|
||||
NORETURN(static void name_to_backref_error(VALUE name));
|
||||
static void
|
||||
name_to_backref_error(VALUE name)
|
||||
{
|
||||
rb_raise(rb_eIndexError, "undefined group name reference: % "PRIsVALUE,
|
||||
name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1732,8 +1728,11 @@ match_aref(int argc, VALUE *argv, VALUE match)
|
|||
/* fall through */
|
||||
case T_STRING:
|
||||
p = StringValuePtr(idx);
|
||||
num = name_to_backref_number(RMATCH_REGS(match),
|
||||
RMATCH(match)->regexp, p, p + RSTRING_LEN(idx));
|
||||
if (!rb_enc_compatible(RREGEXP(RMATCH(match)->regexp)->src, idx) ||
|
||||
(num = name_to_backref_number(RMATCH_REGS(match), RMATCH(match)->regexp,
|
||||
p, p + RSTRING_LEN(idx))) < 1) {
|
||||
name_to_backref_error(idx);
|
||||
}
|
||||
return rb_reg_nth_match(num, match);
|
||||
|
||||
default:
|
||||
|
@ -3342,7 +3341,12 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
|
|||
name_end += c == -1 ? mbclen(name_end, e, str_enc) : clen;
|
||||
}
|
||||
if (name_end < e) {
|
||||
no = name_to_backref_number(regs, regexp, name, name_end);
|
||||
VALUE n = rb_str_subseq(str, (long)(name - RSTRING_PTR(str)),
|
||||
(long)(name_end - name));
|
||||
if (!rb_enc_compatible(RREGEXP(regexp)->src, n) ||
|
||||
(no = name_to_backref_number(regs, regexp, name, name_end)) < 1) {
|
||||
name_to_backref_error(n);
|
||||
}
|
||||
p = s = name_end + clen;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "ruby/ruby.h"
|
||||
#include "ruby/re.h"
|
||||
#include "ruby/encoding.h"
|
||||
#include "internal.h"
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
@ -1195,6 +1196,7 @@ ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int s
|
|||
}
|
||||
else {
|
||||
value = rb_obj_as_string(value);
|
||||
if (sign == ' ') value = QUOTE(value);
|
||||
}
|
||||
enc = rb_enc_compatible(result, value);
|
||||
if (enc) {
|
||||
|
|
|
@ -22,6 +22,12 @@ class Test_SPrintf < Test::Unit::TestCase
|
|||
assert_equal("{<#{self.class}:#{object_id}>}", Bug::Printf.v(self))
|
||||
end
|
||||
|
||||
def test_quote
|
||||
assert_equal('["\n"]', Bug::Printf.q("\n"))
|
||||
assert_equal('[aaa]', Bug::Printf.q('aaa'))
|
||||
assert_equal('[a a]', Bug::Printf.q('a a'))
|
||||
end
|
||||
|
||||
def test_encoding
|
||||
def self.to_s
|
||||
"\u{3042 3044 3046 3048 304a}"
|
||||
|
|
|
@ -150,6 +150,15 @@ class TestRegexp < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_named_capture_nonascii
|
||||
bug9903 = '[ruby-dev:48278] [Bug #9903]'
|
||||
|
||||
key = "\xb1\xb2".force_encoding(Encoding::EUC_JP)
|
||||
m = /(?<#{key}>.*)/.match("xxx")
|
||||
assert_equal("xxx", m[key])
|
||||
assert_raise(IndexError, bug9903) {m[key.dup.force_encoding(Encoding::Shift_JIS)]}
|
||||
end
|
||||
|
||||
def test_assign_named_capture
|
||||
assert_equal("a", eval('/(?<foo>.)/ =~ "a"; foo'))
|
||||
assert_equal("a", eval('foo = 1; /(?<foo>.)/ =~ "a"; foo'))
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#define RUBY_VERSION "2.0.0"
|
||||
#define RUBY_RELEASE_DATE "2014-08-31"
|
||||
#define RUBY_PATCHLEVEL 542
|
||||
#define RUBY_RELEASE_DATE "2014-09-03"
|
||||
#define RUBY_PATCHLEVEL 543
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2014
|
||||
#define RUBY_RELEASE_MONTH 8
|
||||
#define RUBY_RELEASE_DAY 31
|
||||
#define RUBY_RELEASE_MONTH 9
|
||||
#define RUBY_RELEASE_DAY 3
|
||||
|
||||
#include "ruby/version.h"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue