Skip to content

Commit abbd967

Browse files
fix(web): PR comment hover excerpts no longer end in a replacement character (pingdotgg#35111)
1 parent b2e86d7 commit abbd967

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ describe("pull request timeline", () => {
364364
for (const url of [pr, `${pr}/files`, `${pr}/checks`, `${pr}#issuecomment-6`]) {
365365
expect(pullRequestLinkSubject(url, activity), url).toBeNull();
366366
}
367+
// An emoji straddling the cut is dropped whole rather than split into a lone surrogate.
368+
const long = {
369+
...activity,
370+
comments: [{ ...activity.comments[0]!, body: `${"i ".repeat(139)}😀bb` }],
371+
};
372+
const cut = pullRequestLinkSubject(`${pr}#issuecomment-5`, long);
373+
const excerpt = cut && "excerpt" in cut ? cut.excerpt : null;
374+
expect(excerpt).toMatch(/^(?:i ?)+…$/u);
367375
});
368376

369377
it("orders host timestamps by instant across offsets and fractional seconds", () => {

‎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)