diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index fa6cc3934..c0726c1b6 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -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) { diff --git a/src/highlight.cpp b/src/highlight.cpp index 027756236..79f548933 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -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(0x10FFFF); in_pos++; break; }