Skip to content

fix: return nil for a remote url that cannot be fetched - #390

Merged
markdumay merged 3 commits into
mainfrom
fix/2338-remote-getmatch
Nov 6, 2026
Merged

markdumay merged 3 commits into
mainfrom
fix/2338-remote-getmatch

Conversation

@markdumay

Copy link
Copy Markdown
Collaborator

Fixes gethinode/hinode#2338

Summary

When a remote URL can't be fetched, utilities/GetResource.html now returns nil. It no longer passes that URL on to resources.GetMatch as a local asset pattern.

Before this change, any URL that started with http and failed to download went through the asset fallback.

The fallback is now skipped only for a URL that starts with http:// or https://, in any letter case.

  • Asset names that merely start with "http", such as http-logo.jpg or HTTP-x.jpg, still resolve.
  • Protocol-relative //…, single-slash http:/… and other schemes behave exactly as before.
  • Remote URLs that fetch successfully, including the cache-bypass retry, are unchanged.

Tests

A new getresource golden group adds 13 cases:

  • page resources
  • relative and absolute asset paths
  • assets whose names start with http
  • protocol-relative and single-slash forms
  • three unreachable remote URLs

The remote URLs are denied by Hugo's default security policy, so no case touches the network. The test runner wraps this group's calls in try, so each case that errors is recorded as "error".

The new cases fail on main: the three unreachable-remote cases give "error". pnpm test passes with the fix. No existing golden file changes.

An independent review compared main and this branch on 75 URL forms, with Hugo's default security policy and with a permissive policy against a local server. The only differences are the unfetchable http(s):// URLs.

🤖 Generated with Claude Code

markdumay and others added 3 commits November 6, 2026 13:21
GetResource passed a remote url to resources.GetMatch when both
download attempts failed. GetMatch treats the url as an asset pattern:
a "[" in it fails the build with a glob syntax error, and on Windows
the ":" in the url fails the build as an invalid path. The asset
fallback now runs only for urls that are not remote.

The getresource test group covers page resources, assets and two
unfetchable remote urls. The live-editing renderer skips the group,
since its harness replaces GetResource with a stub.

Refs gethinode/hinode#2338

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GetResource skipped the asset fallback for every url that starts with
"http", so an asset name such as "http-logo.jpg" returned nil instead
of the site asset. The fallback is now skipped only for a url that
opens with the scheme "https://" or "https://", in any letter case.
Other urls reach resources.GetMatch as they did before 980bc43.

The getresource group adds three asset names that start with "http",
in lower and upper case, an unreachable "https://" url, a
protocol-relative url and a glob pattern that contains a url.

Refs gethinode/hinode#2338

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The getresource runner now wraps GetResource in try and records a
failed call as "error", so a case whose url reaches resources.GetMatch
with an invalid pattern does not stop the build.

The new case "http:/127.0.0.1:1/img/[x.png" has one slash after the
scheme, so the asset fallback still runs and its "[" fails in GetMatch,
as it does on main. With the partial from main, each unreachable
remote case now fails as its own "error" line in the golden diff.

Refs gethinode/hinode#2338

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@markdumay
markdumay enabled auto-merge November 6, 2026 12:59
@markdumay
markdumay merged commit f22f45b into main Nov 6, 2026
13 checks passed
@markdumay

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 6.18.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mod-utils: GetResource passes an unfetchable remote URL to resources.GetMatch, failing Windows builds

1 participant