Keep escape parsing linear
test / test (pull_request) Successful in 6s

Authored-By: Codex (GPT-5) <noreply@openai.com>
This commit is contained in:
2026-08-27 17:05:40 +00:00
parent 9c07c5f32d
commit 5ce83cdf13
+9 -8
View File
@@ -40,6 +40,7 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk '
visible="" visible=""
pos=1 pos=1
backslash_run=0
while (pos <= length(line)) { while (pos <= length(line)) {
if (in_comment) { if (in_comment) {
rest=substr(line, pos) rest=substr(line, pos)
@@ -51,16 +52,11 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk '
visible=visible " " visible=visible " "
pos += comment_end + 2 pos += comment_end + 2
in_comment=0 in_comment=0
backslash_run=0
continue continue
} }
escaped=0 if (substr(line, pos, 1) == "`" && backslash_run % 2 == 0) {
escape_pos=pos - 1
while (escape_pos >= 1 && substr(line, escape_pos, 1) == "\\") {
escaped++
escape_pos--
}
if (substr(line, pos, 1) == "`" && escaped % 2 == 0) {
ticks=1 ticks=1
while (substr(line, pos + ticks, 1) == "`") ticks++ while (substr(line, pos + ticks, 1) == "`") ticks++
close_pos=pos + ticks close_pos=pos + ticks
@@ -77,6 +73,7 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk '
if (found_close) { if (found_close) {
visible=visible substr(line, pos, close_pos + ticks - pos) visible=visible substr(line, pos, close_pos + ticks - pos)
pos=close_pos + ticks pos=close_pos + ticks
backslash_run=0
continue continue
} }
} }
@@ -85,9 +82,13 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk '
visible=visible " " visible=visible " "
in_comment=1 in_comment=1
pos += 4 pos += 4
backslash_run=0
continue continue
} }
visible=visible substr(line, pos, 1) char=substr(line, pos, 1)
visible=visible char
if (char == "\\") backslash_run++
else backslash_run=0
pos++ pos++
} }
print visible print visible