From 942308bf7233a3edaf1f5efb7303881d955e08e5 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 29 Sep 2022 17:16:42 +0200 Subject: [PATCH] highlight: Unicode above 0x10FFFF is an error This should really just be using read_unquoted_escape, where this was changed in #1107 --- src/fish_tests.cpp | 14 ++++++++++++++ src/highlight.cpp | 2 ++ 2 files changed, 16 insertions(+) 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; }