[Feature #18367]
This commit is contained in:
Yusuke Endoh 2022-02-01 16:32:38 +09:00
Родитель 36e31b09cd
Коммит f207f7a193
3 изменённых файлов: 13 добавлений и 53 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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