Skip to content

Commit 9ef52de

Browse files
fix(shared): keep spreadsheet shorthand as inline code (pingdotgg#23203)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 8d23699 commit 9ef52de

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎packages/shared/src/markdownLinks.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ describe("inlineCodeFilePathCandidate", () => {
4040
["/tmp/.../scratchpad/notes.md", null],
4141
["~/projects/…/notes.md", null],
4242
["src/.../main.ts", null],
43+
// regression: #22181 a `:line` suffix does not make an extensionless basename a file
44+
["I/W217:220", null],
45+
["bin/run:12", null],
46+
["docs/README:12", "docs/README:12"],
47+
["./bin/run:12", "./bin/run:12"],
48+
["src/資料.備份:12", "src/資料.備份:12"],
49+
["src/foo.c++:12", "src/foo.c++:12"],
4350
])("distinguishes file paths from code and hostnames in %s", (source, candidate) => {
4451
expect(inlineCodeFilePathCandidate(source)).toBe(candidate);
4552
});

‎packages/shared/src/markdownLinks.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const PATH_SEPARATOR_PATTERN = /[\\/]/;
3737
const ELIDED_PATH_SEGMENT_PATTERN = /(?:^|[\\/])(?:\.{3,}|…)(?:[\\/]|$)/;
3838

3939
const FILE_EXTENSION_PATTERN = /\.[A-Za-z0-9_-]+$/;
40+
const ANY_FILE_EXTENSION_PATTERN = /\.[^./\\]+$/;
4041
const VERSION_SUFFIX_PATTERN = /\d\.\d[^.]*$/;
4142
const NUMERIC_DOTTED_PATTERN = /^\d+(?:\.\d+)+$/;
4243

@@ -200,7 +201,17 @@ export function inlineCodeFilePathCandidate(codeText: string): string | null {
200201
.split(/[\\/]/)
201202
.at(-1) ?? "";
202203
if (VERSION_SUFFIX_PATTERN.test(basename)) return null;
203-
if (!hasPosition && !FILE_EXTENSION_PATTERN.test(basename)) return null;
204+
if (!FILE_EXTENSION_PATTERN.test(basename)) {
205+
if (!hasPosition) return null;
206+
// A `:line` suffix alone does not make `I/W217:220` a file reference.
207+
if (
208+
withoutPosition.includes("/") &&
209+
!ANY_FILE_EXTENSION_PATTERN.test(basename) &&
210+
!EXTENSIONLESS_FILE_NAMES.has(basename)
211+
) {
212+
return null;
213+
}
214+
}
204215
}
205216
return candidate;
206217
}

0 commit comments

Comments
 (0)