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

ruby-changes:71240

From: Yusuke <ko1@a...>
Date: Tue, 22 Feb 2022 11:56:10 +0900 (JST)
Subject: [ruby-changes:71240] f207f7a193 (master): Do not escape error message

https://git.ruby-lang.org/ruby.git/commit/?id=f207f7a193

From f207f7a193dc4e55820e77388edefb5d8fde18d7 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Tue, 1 Feb 2022 16:32:38 +0900
Subject: Do not escape error message

[Feature #18367]
---
 eval_error.c                  | 51 +++++--------------------------------------
 test/ruby/test_exception.rb   | 11 +++++-----
 test/ruby/test_rubyoptions.rb |  4 ++--
 3 files changed, 13 insertions(+), 53 deletions(-)

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) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L79
     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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L133
 	    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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L153
 	    }
 	    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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L164
 			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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L174
 			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| https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L991
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L357
 
     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
-- 
cgit v1.2.1


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

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