Fix crash with set_color --print-colors --background normal

Found in conjunction with #7805.
This commit is contained in:
Fabian Homborg 2021-03-09 13:46:08 +01:00
parent 4762d52e52
commit a7df92e187
2 changed files with 28 additions and 1 deletions

View File

@ -188,13 +188,19 @@ maybe_t<int> builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t
}
}
const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
if (bgcolor && bg.is_none()) {
streams.err.append_format(_(L"%ls: Unknown color '%ls'\n"), argv[0], bgcolor);
return STATUS_INVALID_ARGS;
}
if (print) {
// Hack: Explicitly setting a background of "normal" crashes
// for --print-colors. Because it's not interesting in terms of display,
// just skip it.
if (bgcolor && bg.is_special()) {
bg = rgb_color_t(L"");
}
print_colors(streams, bold, underline, italics, dim, reverse, bg);
return STATUS_CMD_OK;
}

View File

@ -61,3 +61,24 @@ expect_str("white")
expect_str("yellow")
expect_str("normal")
expect_prompt()
# This used to crash
sendline("set_color --print-colors --background normal")
expect_str("black")
expect_str("blue")
expect_str("brblack")
expect_str("brblue")
expect_str("brcyan")
expect_str("brgreen")
expect_str("brmagenta")
expect_str("brred")
expect_str("brwhite")
expect_str("bryellow")
expect_str("cyan")
expect_str("green")
expect_str("magenta")
expect_str("\n\x1b[31mred")
expect_str("\n\x1b[37mwhite")
expect_str("\n\x1b[33myellow")
expect_str("normal")
expect_prompt()