Skip to content

Commit 9469095

Browse files
authored
fix(provider-core): background work notices no longer end in a broken character (#30369)
1 parent 144b78a commit 9469095

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎packages/provider-core/src/server/notification.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ describe("backgroundWorkNotification", () => {
4242
.summary,
4343
'Monitor "Three ticks" reported new output',
4444
);
45+
assert.equal(
46+
backgroundWorkNotification([
47+
{ kind: "command", label: `${"a".repeat(78)}😀 and more`, outcome: "completed" },
48+
]).summary,
49+
`Command "${"a".repeat(78)}…" finished`,
50+
);
4551
});
4652

4753
it("names every piece of work that ended together, without opening one of them", () => {

‎packages/provider-core/src/server/notification.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ const LABEL_MAX_LENGTH = 80;
2525
export function reportLabel(label: string | undefined): string | undefined {
2626
const firstLine = label?.trim().split("\n")[0]?.trim();
2727
if (firstLine === undefined || firstLine.length === 0) return undefined;
28-
return firstLine.length > LABEL_MAX_LENGTH
29-
? `${firstLine.slice(0, LABEL_MAX_LENGTH - 1)}…`
30-
: firstLine;
28+
if (firstLine.length <= LABEL_MAX_LENGTH) return firstLine;
29+
let end = LABEL_MAX_LENGTH - 1;
30+
const previous = firstLine.charCodeAt(end - 1);
31+
const next = firstLine.charCodeAt(end);
32+
if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
33+
end -= 1;
34+
}
35+
return `${firstLine.slice(0, end)}…`;
3136
}
3237

3338
const KIND_NOUN: Record<BackgroundWork["kind"], readonly [string, string]> = {

0 commit comments

Comments
 (0)