diff --git a/packages/shared/src/markdownLinks.test.ts b/packages/shared/src/markdownLinks.test.ts index 3a0def815d211..e8ef1fa268c1b 100644 --- a/packages/shared/src/markdownLinks.test.ts +++ b/packages/shared/src/markdownLinks.test.ts @@ -343,3 +343,22 @@ describe("resolveMarkdownFileLinkTarget", () => { ); }); }); + +describe("inlineCodeFilePathCandidate with a position suffix", () => { + it.each([ + ["I/W217:220", null], + ["A/B12:40", null], + ["Sheet/XFD1:2", null], + ["./I/W217:220", "./I/W217:220"], + ["bin/run:12", "bin/run:12"], + ["scripts/deploy:40", "scripts/deploy:40"], + ["docker/Dockerfile:8", "docker/Dockerfile:8"], + ["src/app.ts:10", "src/app.ts:10"], + ["src/app.ts:10:4", "src/app.ts:10:4"], + ])( + "only treats extensionless %s as a file when it is not a spreadsheet cell", + (source, candidate) => { + expect(inlineCodeFilePathCandidate(source)).toBe(candidate); + }, + ); +}); diff --git a/packages/shared/src/markdownLinks.ts b/packages/shared/src/markdownLinks.ts index 941f26f55c44b..86dbcb2041e50 100644 --- a/packages/shared/src/markdownLinks.ts +++ b/packages/shared/src/markdownLinks.ts @@ -27,6 +27,7 @@ const PATH_SEPARATOR_PATTERN = /[\\/]/; const FILE_EXTENSION_PATTERN = /\.[A-Za-z0-9_-]+$/; const VERSION_SUFFIX_PATTERN = /\d\.\d[^.]*$/; +const SPREADSHEET_CELL_PATTERN = /^[A-Za-z]{1,3}\d+$/; const NUMERIC_DOTTED_PATTERN = /^\d+(?:\.\d+)+$/; const POSIX_FILE_ROOT_PREFIXES = [ @@ -184,7 +185,14 @@ export function inlineCodeFilePathCandidate(codeText: string): string | null { .split(/[\\/]/) .at(-1) ?? ""; if (VERSION_SUFFIX_PATTERN.test(basename)) return null; - if (!hasPosition && !FILE_EXTENSION_PATTERN.test(basename)) return null; + // A position vouches for an extensionless file (`bin/run:12`), but not for + // spreadsheet cell shorthand (`I/W217:220`). + if ( + !FILE_EXTENSION_PATTERN.test(basename) && + (!hasPosition || SPREADSHEET_CELL_PATTERN.test(basename)) + ) { + return null; + } } return candidate; }