1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

re.c: class name encoding

* re.c (match_inspect): preserve class name encoding by PRIsVALUE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-03-27 09:08:54 +00:00
parent 2dc8f669a8
commit ffdb3ce9b9
2 changed files with 6 additions and 3 deletions

6
re.c
View file

@ -1898,7 +1898,7 @@ match_inspect_name_iter(const OnigUChar *name, const OnigUChar *name_end,
static VALUE static VALUE
match_inspect(VALUE match) match_inspect(VALUE match)
{ {
const char *cname = rb_obj_classname(match); VALUE cname = rb_class_path(rb_obj_class(match));
VALUE str; VALUE str;
int i; int i;
struct re_registers *regs = RMATCH_REGS(match); struct re_registers *regs = RMATCH_REGS(match);
@ -1907,7 +1907,7 @@ match_inspect(VALUE match)
VALUE regexp = RMATCH(match)->regexp; VALUE regexp = RMATCH(match)->regexp;
if (regexp == 0) { if (regexp == 0) {
return rb_sprintf("#<%s:%p>", cname, (void*)match); return rb_sprintf("#<%"PRIsVALUE":%p>", cname, (void*)match);
} }
names = ALLOCA_N(struct backref_name_tag, num_regs); names = ALLOCA_N(struct backref_name_tag, num_regs);
@ -1917,7 +1917,7 @@ match_inspect(VALUE match)
match_inspect_name_iter, names); match_inspect_name_iter, names);
str = rb_str_buf_new2("#<"); str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, cname); rb_str_append(str, cname);
for (i = 0; i < num_regs; i++) { for (i = 0; i < num_regs; i++) {
VALUE v; VALUE v;

View file

@ -887,12 +887,15 @@ class TestRegexp < Test::Unit::TestCase
assert_no_match(/^\p{age=1.1}$/u, "\u2754") assert_no_match(/^\p{age=1.1}$/u, "\u2754")
end end
MatchData_A = eval("class MatchData_\u{3042} < MatchData; self; end")
def test_matchdata def test_matchdata
a = "haystack".match(/hay/) a = "haystack".match(/hay/)
b = "haystack".match(/hay/) b = "haystack".match(/hay/)
assert_equal(a, b, '[ruby-core:24748]') assert_equal(a, b, '[ruby-core:24748]')
h = {a => 42} h = {a => 42}
assert_equal(42, h[b], '[ruby-core:24748]') assert_equal(42, h[b], '[ruby-core:24748]')
assert_match(/#<TestRegexp::MatchData_\u{3042}:/, MatchData_A.allocate.inspect)
end end
def test_regexp_poped def test_regexp_poped