Skip to content

Resolve relative outlinks against <base href> in JSoupParserBolt#2011

Merged
jnioche merged 1 commit into
mainfrom
JSOUPbaseURI
Jul 21, 2026
Merged

Resolve relative outlinks against <base href> in JSoupParserBolt#2011
jnioche merged 1 commit into
mainfrom
JSOUPbaseURI

Conversation

@jnioche

@jnioche jnioche commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

JSoupParserBolt resolved relative outlinks against the document URL, ignoring any <base href> element in the page. For a page served from a sub-path whose <base> points at the domain root, this doubled the path segment.

Example — page https://host/fr/rayons/actualites-reportages/216943 with <base href="https://host/"> and a link href="fr/rayons/stockage-archivage-de-donnees/218725":

  • Expected: https://host/fr/rayons/stockage-archivage-de-donnees/218725
  • Produced: https://host/fr/rayons/actualites-reportages/fr/rayons/stockage-archivage-de-donnees/218725

Fix

Resolve relative links against jsoupDoc.baseUri() instead of the raw document URL. jsoup updates baseUri() to the <base href> value when the element is present, matching browser behaviour, and falls back to the document URL otherwise. This keeps the existing fast resolution path (no per-link abs:href object building).

Test

Added testBaseHrefOutlinkResolution reproducing the doubled-path case. It fails without the fix (producing the doubled URL) and passes with it. Full JSoupParserBoltTest class: 12/12 passing.

Relative links were resolved against the document URL, ignoring any
<base href> element. On a page served from a sub-path with a base
pointing at the domain root this doubled the path segment. Resolve
against jsoupDoc.baseUri() instead, which honours <base> and falls
back to the document URL when absent.
@jnioche jnioche added this to the 3.7.0 milestone Jul 21, 2026
@jnioche
jnioche merged commit cc511f9 into main Jul 21, 2026
2 checks passed
@jnioche
jnioche deleted the JSOUPbaseURI branch July 21, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants