highlight: Unicode above 0x10FFFF is an error

This should really just be using read_unquoted_escape, where this was
changed in #1107
This commit is contained in:
Fabian Boehm
2022-09-29 17:16:42 +02:00
parent d065ea31a9
commit 942308bf72
2 changed files with 16 additions and 0 deletions

View File

@@ -5614,6 +5614,20 @@ static void test_highlighting() {
highlight_tests.push_back({{L"$EMPTY_VARIABLE", highlight_role_t::error}});
highlight_tests.push_back({{L"\"$EMPTY_VARIABLE\"", highlight_role_t::error}});
highlight_tests.push_back({
{L"echo", highlight_role_t::command},
{L"\\UFDFD", highlight_role_t::escape},
});
#if WCHAR_T_BITS > 16
highlight_tests.push_back({
{L"echo", highlight_role_t::command},
{L"\\U10FFFF", highlight_role_t::escape},
});
highlight_tests.push_back({
{L"echo", highlight_role_t::command},
{L"\\U110000", highlight_role_t::error},
});
#endif
const auto saved_flags = fish_features();
mutable_fish_features().set(features_t::ampersand_nobg_in_token, true);
for (const highlight_component_list_t &components : highlight_tests) {

View File

@@ -602,6 +602,8 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
case L'U': {
chars = 8;
max_val = WCHAR_MAX;
// Don't exceed the largest Unicode code point - see #1107.
if (0x10FFFF < max_val) max_val = static_cast<wchar_t>(0x10FFFF);
in_pos++;
break;
}