[前][次][番号順一覧][スレッド一覧]

ruby-changes:50589

From: nobu <ko1@a...>
Date: Tue, 13 Mar 2018 12:49:02 +0900 (JST)
Subject: [ruby-changes:50589] nobu:r62737 (trunk): eval_error.c: reset attributes

nobu	2018-03-13 12:48:56 +0900 (Tue, 13 Mar 2018)

  New Revision: 62737

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62737

  Log:
    eval_error.c: reset attributes
    
    * eval_error.c (print_errinfo): reset all attributes for each
      lines before newlines.

  Modified files:
    trunk/eval_error.c
    trunk/test/ruby/test_exception.rb
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 62736)
+++ test/ruby/test_exception.rb	(revision 62737)
@@ -1262,5 +1262,12 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1262
     assert_operator(message, :end_with?, "\n")
     message = message.gsub(/\e\[[\d;]*m/, '')
     assert_not_operator(message, :end_with?, "\n\n")
+    e = RuntimeError.new("a\n\nb\n\nc")
+    message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do
+      e.full_message
+    end
+    assert_all?(message.lines) do |m|
+      /\e\[\d[;\d]*m[^\e]*\n/ !~ m
+    end
   end
 end
Index: eval_error.c
===================================================================
--- eval_error.c	(revision 62736)
+++ eval_error.c	(revision 62737)
@@ -152,14 +152,32 @@ print_errinfo(const VALUE eclass, const https://github.com/ruby/ruby/blob/trunk/eval_error.c#L152
 		if (highlight) write_warn(str, reset);
 		write_warn2(str, "\n", 1);
 	    }
-	    if (tail) {
-		int eol = einfo[elen-1] == '\n';
-		if (eol && highlight) --elen;
-		if (tail < einfo+elen) {
-		    if (highlight) write_warn(str, bold);
+	    if (tail && einfo+elen > tail) {
+		if (!highlight) {
 		    write_warn2(str, tail, einfo+elen-tail);
-		    if (highlight) write_warn(str, reset);
-		    if (highlight || !eol) write_warn2(str, "\n", 1);
+		    if (einfo[elen-1] != '\n') write_warn2(str, "\n", 1);
+		}
+		else {
+		    elen -= tail - einfo;
+		    einfo = tail;
+		    while (elen > 0) {
+			tail = memchr(einfo, '\n', elen);
+			if (!tail || tail > einfo) {
+			    write_warn(str, bold);
+			    write_warn2(str, einfo, tail ? tail-einfo : elen);
+			    write_warn(str, reset);
+			    if (!tail) {
+				write_warn2(str, "\n", 1);
+				break;
+			    }
+			}
+			elen -= tail - einfo;
+			einfo = tail;
+			do ++tail; while (tail < einfo+elen && *tail == '\n');
+			write_warn2(str, einfo, tail-einfo);
+			elen -= tail - einfo;
+			einfo = tail;
+		    }
 		}
 	    }
 	    else if (!epath) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]