Skip to content

Only parse arguments as URLs when they look like URLs - #29

Merged
Crosse merged 2 commits into
mainfrom
fix/file-urls
Oct 26, 2026
Merged

Crosse merged 2 commits into
mainfrom
fix/file-urls

Conversation

@Crosse

@Crosse Crosse commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Fixes #26.

Every argument went through url.Parse, and plain paths were handled as URLs with no scheme. That caused several bugs:

  • file:// URLs never worked: the original URL string was read from disk instead of the path parsed out of it (file:// URLs don't work for local paths on Windows #26).
  • Windows drive letters looked like a scheme: C:\fonts\x.ttf parsed with the scheme c, which needed a special case.
  • Colons and percent signs in file names: font:bold.ttf parsed with the scheme font, and 100%zz.ttf failed as an invalid URL escape.

Changes

  • Only arguments that contain :// are parsed as URLs. Everything else is treated as a local path, with the existing wildcard handling.
  • file:// URLs are converted to local paths by fileURLToPath. On Windows that handles /C:/... paths and turns file://server/share/... into a UNC path. On other OSes, a file:// URL with a host is rejected.
  • The content-type handling (zip, gzip, tar, or a single font) moves into installData, which local files and downloads share.

Testing

  • TestPathForms: 100%zz.ttf, font:bold.ttf (not on Windows), a file:// URL for a temp file, and an ftp:// URL that must be rejected.
  • TestFileURLToPath: conversion tables for Windows and for other OSes.
  • On Windows 11 ARM64, the URL from file:// URLs don't work for local paths on Windows #26 (file:///C:/.../My%20Fonts/FiraMono-Regular.ttf) now installs, as do a drive-letter path, a name containing %, and an https download.
  • golangci-lint v2.14.0 is clean with GOOS set to windows, linux, darwin, freebsd and openbsd.

🤖 Generated with Claude Code

https://claude.ai/code/session_019v8ctg7o6tZH7zcRwizpF5

Every argument went through url.Parse, with plain paths handled as URLs
without a scheme. That caused several problems:

- file:// URLs never worked: the original URL string was read from disk
  instead of the path parsed out of it.
- Windows drive letters parsed as a scheme ("C:" became "c"), which
  needed a special case.
- File names with a colon ("font:bold.ttf") parsed as a scheme, and
  names with a percent sign ("100%zz.ttf") failed as invalid escapes.

Now only arguments containing "://" are parsed as URLs. file:// URLs are
converted to local paths, including drive letters and UNC hosts on
Windows, and everything else is treated as a local path. The
content-type handling moves into installData so local files and
downloads share it.

Fixes #26.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019v8ctg7o6tZH7zcRwizpF5

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Mixed-case localhost authorities are handled incorrectly, causing valid local file URLs to fail.

1 open issue
What changed in this PR

This PR addresses #26 by separating local paths from URL handling, fixing file:// installation and avoiding URL parsing errors for ordinary filenames.

Changes:

  • Parse arguments as URLs only when they contain ://.
  • Convert file URLs into platform-specific paths and share content handling through installData.
  • Add tests for special filenames, file URL conversion, and unsupported schemes.
File Description
install.go Separates path and URL handling, converts file URLs, and extracts shared installation logic.
install_test.go Adds path-form and platform-specific file URL conversion tests.

Review effort: Balanced

Comment thread install.go Resolved
Host names are case-insensitive, but url.Parse keeps their case, so
file://LOCALHOST/... was rejected on Unix and became a UNC path on
Windows. Compare with strings.EqualFold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019v8ctg7o6tZH7zcRwizpF5
@Crosse
Crosse merged commit b514887 into main Oct 26, 2026
10 checks passed
@Crosse
Crosse deleted the fix/file-urls branch October 26, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

file:// URLs don't work for local paths on Windows

2 participants