@@ -524,6 +524,73 @@ then proper highlighting once block is closed."
524524 (should (or (eq face 'font-lock-keyword-face )
525525 (and (listp face) (memq 'font-lock-keyword-face face))))))))
526526
527+ ; ;; Markdown Escape Restriction
528+
529+ (ert-deftest pi-coding-agent-test-backslash-n-visible-in-chat ()
530+ " Backslash before non-punctuation chars stays visible in chat.
531+ Regression test: markdown-mode hides backslash in \\ n, \\ t, etc.
532+ because `markdown-match-escape' matches backslash + any char.
533+ We override `markdown-regex-escape' buffer-locally to restrict
534+ matching to CommonMark-valid escapes only."
535+ (with-temp-buffer
536+ (pi-coding-agent-chat-mode)
537+ (let ((inhibit-read-only t ))
538+ (insert " Use \\ n for a newline\n " )
539+ (font-lock-ensure )
540+ (goto-char (point-min ))
541+ (search-forward " \\ " nil t )
542+ (let ((inv (get-text-property (1- (point )) 'invisible )))
543+ (should-not inv)))))
544+
545+ (ert-deftest pi-coding-agent-test-backslash-t-visible-in-chat ()
546+ " Backslash before t stays visible in chat."
547+ (with-temp-buffer
548+ (pi-coding-agent-chat-mode)
549+ (let ((inhibit-read-only t ))
550+ (insert " Use \\ t for a tab\n " )
551+ (font-lock-ensure )
552+ (goto-char (point-min ))
553+ (search-forward " \\ " nil t )
554+ (let ((inv (get-text-property (1- (point )) 'invisible )))
555+ (should-not inv)))))
556+
557+ (ert-deftest pi-coding-agent-test-backslash-star-hidden-in-chat ()
558+ " Backslash before * (valid markdown escape) IS hidden.
559+ Ensures the restricted regex preserves intended escape behavior.
560+ Requires preceding text so gfm-mode doesn't classify content as
561+ YAML metadata (which would skip escape matching entirely)."
562+ (with-temp-buffer
563+ (pi-coding-agent-chat-mode)
564+ (let ((inhibit-read-only t ))
565+ (insert " Some preceding text\n\n Escaped: \\ * not bold\n " )
566+ (font-lock-ensure )
567+ (goto-char (point-min ))
568+ (search-forward " \\ " nil t )
569+ (let ((inv (get-text-property (1- (point )) 'invisible )))
570+ (should (eq inv 'markdown-markup ))))))
571+
572+ (ert-deftest pi-coding-agent-test-backslash-in-code-block-unaffected ()
573+ " Backslash in fenced code block is never hidden (existing behavior)."
574+ (with-temp-buffer
575+ (pi-coding-agent-chat-mode)
576+ (let ((inhibit-read-only t ))
577+ (insert " ```\n print(\" hello\\ nworld\" )\n ```\n " )
578+ (font-lock-ensure )
579+ (goto-char (point-min ))
580+ (search-forward " \\ " nil t )
581+ (let ((inv (get-text-property (1- (point )) 'invisible )))
582+ (should-not inv)))))
583+
584+ (ert-deftest pi-coding-agent-test-escape-regex-is-buffer-local ()
585+ " Chat mode sets `markdown-regex-escape' buffer-locally.
586+ Verifies the fix is scoped to our buffer and does not affect
587+ other markdown-mode buffers."
588+ (with-temp-buffer
589+ (pi-coding-agent-chat-mode)
590+ (should (local-variable-p 'markdown-regex-escape ))
591+ (should (equal markdown-regex-escape
592+ pi-coding-agent--markdown-regex-escape))))
593+
527594; ;; User Message Display
528595
529596(ert-deftest pi-coding-agent-test-display-user-message-inserts-text ()
0 commit comments