Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/shared/src/composerContextReferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ describe("labels and reference links", () => {
collectComposerContextReferences(`[${"x".repeat(300)}](t3-context://v1/file/ctx_1)`)[0]
?.label,
).toHaveLength(200);
expect(
collectComposerContextReferences(`[${"x".repeat(199)}😀tail](t3-context://v1/file/ctx_1)`)[0]
?.label,
).toBe("x".repeat(199));
});

it("collects occurrences in document order with offsets, sharing a payload", () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/shared/src/composerContextReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ export function parseComposerContextHref(
}

export function sanitizeComposerContextLabel(label: string, kind: ComposerContextKind): string {
const cleaned = label
const normalized = label
.replace(/[[\]\\\r\n]/g, " ")
.replace(/\s+/g, " ")
.trim()
.slice(0, COMPOSER_CONTEXT_LABEL_MAX_CHARS);
.trim();
let end = COMPOSER_CONTEXT_LABEL_MAX_CHARS;
const before = normalized.charCodeAt(end - 1);
const after = normalized.charCodeAt(end);
if (before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff) end--;
const cleaned = normalized.slice(0, end);
return cleaned.length > 0 ? cleaned : kind;
}

Expand Down
Loading