Skip to content

Commit 86b845a

Browse files
drvossCopilot
andcommitted
imessage keep leading nul cleanup
Co-authored-by: Copilot <[email protected]>
1 parent d95479c commit 86b845a

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

extensions/imessage/src/monitor/echo-cache.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,29 @@ export type SentMessageCache = {
2222
// duplicate delivery (noisy but not lossy) — never message loss.
2323
const SENT_MESSAGE_TEXT_TTL_MS = 4_000;
2424
const SENT_MESSAGE_ID_TTL_MS = 60_000;
25-
const LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS = /^[\u0000\uFEFF\uFFFD\uFFFE\uFFFF]+/u;
25+
const LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS = new Set([
26+
"\u0000",
27+
"\uFEFF",
28+
"\uFFFD",
29+
"\uFFFE",
30+
"\uFFFF",
31+
]);
32+
33+
function stripLeadingAttributedBodyCorruptionMarkers(text: string): string {
34+
let start = 0;
35+
while (start < text.length && LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS.has(text[start] ?? "")) {
36+
start += 1;
37+
}
38+
return start === 0 ? text : text.slice(start);
39+
}
2640

2741
function normalizeEchoTextKey(text: string | undefined): string | null {
2842
if (!text) {
2943
return null;
3044
}
31-
const normalized = text
32-
.replace(/\r\n?/g, "\n")
33-
.trim()
34-
.replace(LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS, "")
35-
.trim();
45+
const normalized = stripLeadingAttributedBodyCorruptionMarkers(
46+
text.replace(/\r\n?/g, "\n").trim(),
47+
).trim();
3648
return normalized ? normalized : null;
3749
}
3850

0 commit comments

Comments
 (0)