Skip to content

Resolve relative links against <base href> when present - #31

Merged
DhanushNehru merged 1 commit into
DevelopersGlobal:mainfrom
jay23606:pr-go/13-resolve-relative-links-against-base-href
Nov 6, 2026
Merged

DhanushNehru merged 1 commit into
DevelopersGlobal:mainfrom
jay23606:pr-go/13-resolve-relative-links-against-base-href

Conversation

@jay23606

@jay23606 jay23606 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Problem

parseHTML resolves relative href and src values against the page URL only. When a page declares a <base href>, links, stylesheets, scripts, forms and feeds resolve against the wrong base, which yields wrong routes and missed assets.

Change

parseHTML now uses the first <base href> in the document, resolved against the page URL, as the base for that page. Pages without a <base> element with an href behave exactly as before.

Testing

  • Added TestParseHTMLBaseHref, which fails on the previous code (base href links [https://fixture.test/site/guide]) and passes with this change.
  • go test -run "^TestParseHTMLBaseHref$" . passes.
  • go test ./... passes.

Regression test: fails on base twice (/base href links [/), passes on fix twice (go test -run "^TestParseHTMLBaseHref$" .)

Fixes #13

@DhanushNehru
DhanushNehru merged commit 89fd248 into DevelopersGlobal:main Nov 6, 2026
3 checks passed
@jay23606
jay23606 deleted the pr-go/13-resolve-relative-links-against-base-href branch November 6, 2026 20:30
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.

Resolve relative links against <base href> when present

2 participants