File tree Expand file tree Collapse file tree
extensions/imessage/src/monitor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,17 +22,29 @@ export type SentMessageCache = {
2222// duplicate delivery (noisy but not lossy) — never message loss.
2323const SENT_MESSAGE_TEXT_TTL_MS = 4_000 ;
2424const 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
2741function 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
You can’t perform that action at this time.
0 commit comments