diff --git a/eval_error.c b/eval_error.c index e2632f4c1b..95a3b04b67 100644 --- a/eval_error.c +++ b/eval_error.c @@ -79,47 +79,6 @@ error_print(rb_execution_context_t *ec) rb_ec_error_print(ec, ec->errinfo); } -static void -write_warnq(VALUE out, VALUE str, const char *ptr, long len) -{ - if (NIL_P(out)) { - const char *beg = ptr; - const long olen = len; - for (; len > 0; --len, ++ptr) { - unsigned char c = *ptr; - switch (c) { - case '\n': case '\t': continue; - } - if (rb_iscntrl(c)) { - char buf[5]; - const char *cc = 0; - if (ptr > beg) rb_write_error2(beg, ptr - beg); - beg = ptr + 1; - cc = ruby_escaped_char(c); - if (cc) { - rb_write_error2(cc, strlen(cc)); - } - else { - rb_write_error2(buf, snprintf(buf, sizeof(buf), "\\x%02X", c)); - } - } - else if (c == '\\') { - rb_write_error2(beg, ptr - beg + 1); - beg = ptr; - } - } - if (ptr > beg) { - if (beg == RSTRING_PTR(str) && olen == RSTRING_LEN(str)) - rb_write_error_str(str); - else - rb_write_error2(beg, ptr - beg); - } - } - else { - rb_str_cat(out, ptr, len); - } -} - #define CSI_BEGIN "\033[" #define CSI_SGR "m" @@ -174,11 +133,11 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA if (RSTRING_PTR(epath)[0] == '#') epath = 0; if ((tail = memchr(einfo, '\n', elen)) != 0) { - write_warnq(str, emesg, einfo, tail - einfo); + write_warn2(str, einfo, tail - einfo); tail++; /* skip newline */ } else { - write_warnq(str, emesg, einfo, elen); + write_warn_str(str, emesg); } if (epath) { write_warn(str, " ("); @@ -194,7 +153,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA } if (tail && einfo+elen > tail) { if (!highlight) { - write_warnq(str, emesg, tail, einfo+elen-tail); + write_warn2(str, tail, einfo+elen-tail); if (einfo[elen-1] != '\n') write_warn2(str, "\n", 1); } else { @@ -205,7 +164,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA tail = memchr(einfo, '\n', elen); if (!tail || tail > einfo) { write_warn(str, bold); - write_warnq(str, emesg, einfo, tail ? tail-einfo : elen); + write_warn2(str, einfo, tail ? tail-einfo : elen); write_warn(str, reset); if (!tail) { write_warn2(str, "\n", 1); @@ -215,7 +174,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA elen -= tail - einfo; einfo = tail; do ++tail; while (tail < einfo+elen && *tail == '\n'); - write_warnq(str, emesg, einfo, tail-einfo); + write_warn2(str, einfo, tail-einfo); elen -= tail - einfo; einfo = tail; } diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 306ef200c5..0a0af390ca 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -991,11 +991,12 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end assert_not_nil(e) assert_include(e.message, "\0") - assert_in_out_err([], src, [], [], *args, **opts) do |_, err,| - err.each do |e| - assert_not_include(e, "\0") - end - end + # Disabled by [Feature #18367] + #assert_in_out_err([], src, [], [], *args, **opts) do |_, err,| + # err.each do |e| + # assert_not_include(e, "\0") + # end + #end e end diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 8839efd04a..4adb03edef 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -357,9 +357,9 @@ class TestRubyOptions < Test::Unit::TestCase assert_in_out_err(%W(-\r -e) + [""], "", [], []) - assert_in_out_err(%W(-\rx), "", [], /invalid option -\\r \(-h will show valid options\) \(RuntimeError\)/) + assert_in_out_err(%W(-\rx), "", [], /invalid option -\r \(-h will show valid options\) \(RuntimeError\)/) - assert_in_out_err(%W(-\x01), "", [], /invalid option -\\x01 \(-h will show valid options\) \(RuntimeError\)/) + assert_in_out_err(%W(-\x01), "", [], /invalid option -\x01 \(-h will show valid options\) \(RuntimeError\)/) assert_in_out_err(%w(-Z), "", [], /invalid option -Z \(-h will show valid options\) \(RuntimeError\)/) end