Skip to content

Commit 569084d

Browse files
fix(web): PR comment hover excerpts no longer end in a replacement character
The excerpt cut at a fixed UTF-16 length, so an emoji straddling the cut left a lone high surrogate before the ellipsis. Back off one code unit when the cut lands inside a surrogate pair, like the other preview cuts. Fixes #35082 AI-assisted; verified with the tests and tools listed above.
1 parent 0b69559 commit 569084d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎apps/web/src/components/pullRequest/pullRequestDetail.logic.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,12 @@ function markdownExcerpt(body: string): string | null {
732732
.replace(/\s+/gu, " ")
733733
.trim();
734734
if (text === "") return null;
735-
return text.length > LINK_EXCERPT_LENGTH ? `${text.slice(0, LINK_EXCERPT_LENGTH - 1)}…` : text;
735+
if (text.length <= LINK_EXCERPT_LENGTH) return text;
736+
let end = LINK_EXCERPT_LENGTH - 1;
737+
// Never end on a lone high surrogate.
738+
const last = text.charCodeAt(end - 1);
739+
if (last >= 0xd800 && last <= 0xdbff) end -= 1;
740+
return `${text.slice(0, end)}…`;
736741
}
737742

738743
/** The comment or commit a pull request link names, for its hover card; null for the PR itself. */

0 commit comments

Comments
 (0)