From e8f09f93930e0c99769e4e4ded2342638ac3d5e5 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 10 Mar 2017 11:43:25 +0900 Subject: Raise special Exception when exception class is redefined; fix #3493 --- src/class.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/class.c b/src/class.c index 0922b3cff..fdb10d271 100644 --- a/src/class.c +++ b/src/class.c @@ -330,8 +330,14 @@ mrb_class_get(mrb_state *mrb, const char *name) MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name) { - struct RClass *exc = mrb_class_get_under(mrb, mrb->object_class, name); - struct RClass *e = exc; + struct RClass *exc, *e; + mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), + mrb_intern_cstr(mrb, name)); + + if (mrb_type(c) != MRB_TT_CLASS) { + mrb_raise(mrb, mrb->eException_class, "exception corrupted"); + } + exc = e = mrb_class_ptr(c); while (e) { if (e == mrb->eException_class) -- cgit v1.2.3 From 2f299cf4dc930890faecbe5d54235996e37a4c8b Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 10 Mar 2017 12:36:58 +0900 Subject: Simplify expression; ref #3490 --- src/vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm.c b/src/vm.c index e9c8b81bc..2f999449d 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1345,7 +1345,7 @@ RETRY_TRY_BLOCK: int a = GETARG_A(i); int n = GETARG_C(i); - if (mid == 0 || !mrb->c->ci->target_class) { + if (mid == 0 || !ci->target_class) { mrb_value exc; exc = mrb_exc_new_str_lit(mrb, E_NOMETHOD_ERROR, "super called outside of method"); -- cgit v1.2.3 From ff262f2133a5ffed2051e50a3fbcacf4c6920ecd Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 10 Mar 2017 12:37:19 +0900 Subject: Update ci->mid according to surrounding scope; fix #3490 --- src/vm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vm.c b/src/vm.c index 2f999449d..37f62584b 100644 --- a/src/vm.c +++ b/src/vm.c @@ -569,6 +569,7 @@ eval_under(mrb_state *mrb, mrb_value self, mrb_value blk, struct RClass *c) p = mrb_proc_ptr(blk); ci->proc = p; ci->argc = 1; + ci->mid = ci[-1].mid; if (MRB_PROC_CFUNC_P(p)) { stack_extend(mrb, 3, 0); mrb->c->stack[0] = self; -- cgit v1.2.3 From b56ad8d1223c5419bde4338692d111eaa39444c2 Mon Sep 17 00:00:00 2001 From: ksss Date: Fri, 10 Mar 2017 22:22:06 +0900 Subject: \1 sequences as empty strings --- mrblib/string.rb | 2 ++ test/t/string.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/mrblib/string.rb b/mrblib/string.rb index b13cfd69a..6f698e321 100644 --- a/mrblib/string.rb +++ b/mrblib/string.rb @@ -34,6 +34,8 @@ class String m when "'" post + when "1", "2", "3", "4", "5", "6", "7", "8", "9" + "" else self[j, 2] end diff --git a/test/t/string.rb b/test/t/string.rb index 442c95bf7..ace6638cf 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -365,6 +365,7 @@ assert('String#gsub', '15.2.10.5.18') do assert_equal('$$a$$', '##a##'.gsub('##'){|w| '$$' }, 'mruby/mruby#847 another case with block') assert_equal('A', 'a'.gsub('a', 'A')) assert_equal('A', 'a'.gsub('a'){|w| w.capitalize }) + assert_equal("<><>", 'a'.gsub('a', '<\0><\1><\2>')) end assert('String#gsub with backslash') do -- cgit v1.2.3