Skip to content

Commit ead51f7

Browse files
committed
fix: avoid linkifying custom URI Windows paths
1 parent c7dde07 commit ead51f7

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/features/messages/components/Markdown.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,18 @@ describe("Markdown file-like href behavior", () => {
448448
expect(container.textContent).toContain("/workspace/settings#L12");
449449
});
450450

451+
it("does not linkify Windows file paths embedded in custom URIs", () => {
452+
const { container } = render(
453+
<Markdown
454+
value="Open vscode://file/C:/repo/src/App.tsx:12 in VS Code."
455+
className="markdown"
456+
/>,
457+
);
458+
459+
expect(container.querySelector(".message-file-link")).toBeNull();
460+
expect(container.textContent).toContain("vscode://file/C:/repo/src/App.tsx:12");
461+
});
462+
451463
it("does not turn workspace review #L anchors in inline code into file links", () => {
452464
const { container } = render(
453465
<Markdown

src/features/messages/utils/messageFileLinks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const FILE_PATH_MATCH = new RegExp(`^${FILE_PATH_PATTERN.source}$`);
4545
const TRAILING_PUNCTUATION = new Set([".", ",", ";", ":", "!", "?", ")", "]", "}"]);
4646
const LETTER_OR_NUMBER_PATTERN = /[\p{L}\p{N}.]/u;
4747
const URL_SCHEME_PREFIX_PATTERN = /[a-zA-Z][a-zA-Z0-9+.-]*:\/\/\/?$/;
48+
const EMBEDDED_URL_SCHEME_PATTERN = /[a-zA-Z][a-zA-Z0-9+.-]*:\/\/\S*$/;
4849
const PATH_CANDIDATE_PREFIX_BOUNDARY_PATTERN = /[\s<>"'()`[\]{}]/u;
4950
const LIKELY_LOCAL_ABSOLUTE_PATH_PREFIXES = [
5051
"/Users/",
@@ -198,7 +199,10 @@ function isPathCandidate(
198199
leadingText: string,
199200
previousChar: string,
200201
) {
201-
if (URL_SCHEME_PREFIX_PATTERN.test(leadingText)) {
202+
if (
203+
URL_SCHEME_PREFIX_PATTERN.test(leadingText) ||
204+
EMBEDDED_URL_SCHEME_PATTERN.test(leadingText)
205+
) {
202206
return false;
203207
}
204208
if (/^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\")) {

src/features/messages/utils/remarkFileLinks.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,11 @@ describe("remarkFileLinks", () => {
6666
);
6767
expect(tree.children?.[0]?.children?.map((child) => child.type)).toEqual(["text"]);
6868
});
69+
70+
it("does not split custom URIs that embed Windows file paths", () => {
71+
const tree = runRemarkFileLinks(
72+
textParagraph("Open vscode://file/C:/repo/src/App.tsx:12 in VS Code."),
73+
);
74+
expect(tree.children?.[0]?.children?.map((child) => child.type)).toEqual(["text"]);
75+
});
6976
});

0 commit comments

Comments
 (0)