From 109abbeed40c776fdc33bd5c9344b6865122ef6d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 28 May 2020 20:58:46 +1000 Subject: [PATCH] Fix invalid regions with begin > end being generated Fixes #3495 --- src/highlighters.cc | 10 +++++----- .../3495-crash-highlighting-hidden-lines/cmd | 0 .../regression/3495-crash-highlighting-hidden-lines/in | 1 + .../regression/3495-crash-highlighting-hidden-lines/rc | 9 +++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 test/regression/3495-crash-highlighting-hidden-lines/cmd create mode 100644 test/regression/3495-crash-highlighting-hidden-lines/in create mode 100644 test/regression/3495-crash-highlighting-hidden-lines/rc diff --git a/src/highlighters.cc b/src/highlighters.cc index ecc84481..ac33cf4f 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -2131,16 +2131,16 @@ private: auto end_it = matches.find_matching_end(buffer, beg_it->end_coord(), region.value->match_capture() ? beg_it->capture(buffer) : Optional{}); - if (end_it == matches.end_matches.end() or end_it->end_coord() >= range.end) + if (end_it == matches.end_matches.end() or end_it->end_coord() >= range.end) // region continue past range end { - regions.push_back({ {beg_it->line, beg_it->begin}, - range.end, - region.key }); + auto begin_coord = beg_it->begin_coord(); + if (begin_coord < range.end) + regions.push_back({begin_coord, range.end, region.key}); break; } auto end_coord = end_it->end_coord(); - regions.push_back({ beg_it->begin_coord(), end_coord, region.key }); + regions.push_back({beg_it->begin_coord(), end_coord, region.key}); // With empty begin and end matches (for example if the regexes // are /"\K/ and /(?=")/), that case can happen, and would diff --git a/test/regression/3495-crash-highlighting-hidden-lines/cmd b/test/regression/3495-crash-highlighting-hidden-lines/cmd new file mode 100644 index 00000000..e69de29b diff --git a/test/regression/3495-crash-highlighting-hidden-lines/in b/test/regression/3495-crash-highlighting-hidden-lines/in new file mode 100644 index 00000000..c196171a --- /dev/null +++ b/test/regression/3495-crash-highlighting-hidden-lines/in @@ -0,0 +1 @@ +{}{<>} diff --git a/test/regression/3495-crash-highlighting-hidden-lines/rc b/test/regression/3495-crash-highlighting-hidden-lines/rc new file mode 100644 index 00000000..dfe47350 --- /dev/null +++ b/test/regression/3495-crash-highlighting-hidden-lines/rc @@ -0,0 +1,9 @@ +add-highlighter global/rs regions +add-highlighter global/rs/r1 region \{ \} ref sub + +add-highlighter shared/sub regions +add-highlighter shared/sub/r2 region < > group +add-highlighter shared/sub/r2/ regex X 0:red + +declare-option range-specs replaced_part 1 1.2,1.4|Placeholder +add-highlighter global/ replace-ranges replaced_part