summaryrefslogtreecommitdiff
path: root/syntax.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-05-21 11:56:56 -0400
committerpommicket <pommicket@gmail.com>2023-05-21 11:56:56 -0400
commit44413aca2385fceb7b6c74cb3e764271fdc077e7 (patch)
treea6fd4b730065d8abceaff93c4b88a17ecf80051d /syntax.c
parent2775060cc34b6131535591671225ae2f7727ef5d (diff)
fix highlighting of javascript regex literals
Diffstat (limited to 'syntax.c')
-rw-r--r--syntax.c9
1 files changed, 6 insertions, 3 deletions
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;