diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2022-02-01 16:32:38 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2022-02-22 11:55:40 +0900 |
commit | f207f7a193dc4e55820e77388edefb5d8fde18d7 (patch) | |
tree | 733841bdb334ec44deb69e8068b554fedf5ccbd7 /eval_error.c | |
parent | 36e31b09cddbadd6acc4becb83a8c4bddfb2af1f (diff) | |
download | ruby-f207f7a193dc4e55820e77388edefb5d8fde18d7.tar.gz |
Do not escape error message
[Feature #18367]
Diffstat (limited to 'eval_error.c')
-rw-r--r-- | eval_error.c | 51 |
1 files changed, 5 insertions, 46 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) 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; } |