GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): one-letter link schemes no longer become file links on W… · Pipyakas/t3code@a61291e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • fileLinks.test.ts
    • fileLinks.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/shared/src/fileLinks.test.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ describe("parseFileUrlHref", () => {
103103
it.each(["https://example.com/a.ts", "file://%", "/Users/julius/a.ts"])("rejects %s", (href) => {
104104
expect(parseFileUrlHref(href)).toBeNull();
105105
});
106+
107+
it("rejects one-letter schemes that Chromium on Windows reads as drive letters", () => {
108+
const NativeURL = URL;
109+
using _url = vi.spyOn(globalThis, "URL").mockImplementation(function (input: string | URL) {
110+
const drive = /^([a-z]):/i.exec(String(input));
111+
return drive
112+
? new NativeURL(`file:///${drive[1]!.toUpperCase()}:/${String(input).slice(2)}`)
113+
: new NativeURL(input);
114+
});
115+
expect(parseFileUrlHref("d:x")).toBeNull();
116+
});
106117
});
107118

108119
describe("splitFilePathPosition", () => {
Collapse file

‎packages/shared/src/fileLinks.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/fileLinks.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const POSITION_HASH_PATTERN = /^#L(\d+)(?:C(\d+)|-L?(\d+))?$/i;
1313
export function parseFileUrlHref(
1414
href: string,
1515
): { readonly path: string; readonly hash: string } | null {
16+
// Chromium on Windows parses any one-letter scheme as a drive letter
17+
// (`new URL("d:x")` is `file:///D:/x`), so the protocol check alone would turn
18+
// such links into file links only on Windows.
19+
if (!href.trim().toLowerCase().startsWith("file:")) return null;
1620
try {
1721
const parsed = new URL(href);
1822
if (parsed.protocol.toLowerCase() !== "file:") return null;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.