Skip to content

Commit c458380

Browse files
committed
fix(web): normalize duplicate Windows file chip paths
1 parent 228c58c commit c458380

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎apps/web/src/components/ChatMarkdown.test.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ describe("ChatMarkdown Windows file links", () => {
105105
},
106106
);
107107

108+
it.each([true, false])(
109+
"does not disambiguate the same file in links and inline code with parseRawHtml=%s",
110+
(parseRawHtml) => {
111+
const path = String.raw`C:\Users\shawn\project\src\main.ts`;
112+
const html = renderToStaticMarkup(
113+
<ChatMarkdown
114+
cwd="C:/Users/shawn/project"
115+
text={`[Source](${path}) and \`${path}\``}
116+
lineBreaks={!parseRawHtml}
117+
parseRawHtml={parseRawHtml}
118+
/>,
119+
);
120+
121+
expect(html.match(/chat-markdown-file-link/g)).toHaveLength(2);
122+
expect(html).not.toContain("main.ts ·");
123+
},
124+
);
125+
108126
it.each([true, false])("preserves reference links with parseRawHtml=%s", (parseRawHtml) => {
109127
const html = renderToStaticMarkup(
110128
<ChatMarkdown

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -882,14 +882,12 @@ function pathParentSegments(path: string): string[] {
882882
function buildFileLinkParentSuffixByPath(filePaths: ReadonlyArray<string>): Map<string, string> {
883883
const groups = new Map<string, Set<string>>();
884884
for (const filePath of filePaths) {
885-
const pathSegments = filePath
886-
.replaceAll("\\", "/")
887-
.split("/")
888-
.filter((segment) => segment.length > 0);
885+
const normalizedPath = filePath.replaceAll("\\", "/");
886+
const pathSegments = normalizedPath.split("/").filter((segment) => segment.length > 0);
889887
const basename = pathSegments[pathSegments.length - 1];
890888
if (!basename) continue;
891889
const group = groups.get(basename) ?? new Set<string>();
892-
group.add(filePath);
890+
group.add(normalizedPath);
893891
groups.set(basename, group);
894892
}
895893

@@ -1615,7 +1613,9 @@ function ChatMarkdown({
16151613
copyMarkdown: string,
16161614
className?: string,
16171615
) => {
1618-
const parentSuffix = fileLinkParentSuffixByPath.get(fileLinkMeta.filePath);
1616+
const parentSuffix = fileLinkParentSuffixByPath.get(
1617+
fileLinkMeta.filePath.replaceAll("\\", "/"),
1618+
);
16191619
const labelParts = [fileLinkMeta.basename];
16201620
if (typeof parentSuffix === "string" && parentSuffix.length > 0) {
16211621
labelParts.push(parentSuffix);

0 commit comments

Comments
 (0)