diff --git a/eval_error.c b/eval_error.c index 346b76ed5f..d909125fbd 100644 --- a/eval_error.c +++ b/eval_error.c @@ -129,15 +129,13 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA } else { const char *tail = 0; - long len = elen; if (emesg == Qundef && highlight) write_warn(str, bold); if (RSTRING_PTR(epath)[0] == '#') epath = 0; if ((tail = memchr(einfo, '\n', elen)) != 0) { - len = tail - einfo; + write_warn2(str, einfo, tail - einfo); tail++; /* skip newline */ - write_warn2(str, einfo, len); } else { write_warn_str(str, emesg); @@ -159,7 +157,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA if (einfo[elen-1] == '\n') --elen; write_warn(str, bold); } - write_warn2(str, tail, elen - len - 1); + if (tail < einfo+elen) write_warn2(str, tail, einfo+elen-tail); } if (tail ? (highlight || einfo[elen-1] != '\n') : !epath) { if (highlight) write_warn(str, reset); diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index bb70bf508f..6532fecea9 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1254,5 +1254,13 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| _, err2, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; end"], '', true, true) assert_equal(err2, out1) + + if $stderr.tty? + e = RuntimeError.new("a\n") + message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do + e.full_message + end + assert_operator(message, :end_with?, "\n") + end end end