From 44413aca2385fceb7b6c74cb3e764271fdc077e7 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sun, 21 May 2023 11:56:56 -0400 Subject: fix highlighting of javascript regex literals --- control | 2 +- syntax.c | 9 ++++++--- ted.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/control b/control index 4c80044..464db3b 100644 --- a/control +++ b/control @@ -1,5 +1,5 @@ Package: ted -Version: 2.3 +Version: 2.3.1 Section: text Priority: optional Architecture: amd64 diff --git a/syntax.c b/syntax.c index 5a0e42a..258ff20 100644 --- a/syntax.c +++ b/syntax.c @@ -1340,10 +1340,13 @@ static void syntax_highlight_javascript_like( } if (!dealt_with && !in_multiline_comment && !in_string) { // this is not foolproof for detecting regex literals - // but should handle all "reasonable" uses of regex. + // but should handle all "reasonable" uses of regex, + // while not accidentally treating division as regex. bool is_regex = i == 0 // slash is first char in line - || is32_space(line[i-1]) // slash preceded by space - || (line[i-1] <= 128 && strchr(";({[=,:", (char)line[i-1])); // slash preceded by any of these characters + // slash preceded by space and followed by non-space + || (is32_space(line[i-1]) && i + 1 < line_len && !is32_space(line[i+1])) + // slash preceded by any of these characters + || (line[i-1] <= 128 && strchr(";({[=,:", (char)line[i-1])); if (is_regex) { in_string = true; string_is_regex = true; diff --git a/ted.h b/ted.h index 608c41e..5b79599 100644 --- a/ted.h +++ b/ted.h @@ -28,7 +28,7 @@ extern "C" { #include "sdl-inc.h" /// Version number -#define TED_VERSION "2.3" +#define TED_VERSION "2.3.1" /// Version string #define TED_VERSION_FULL "ted v. " TED_VERSION /// Maximum path size ted handles. -- cgit v1.2.3