Skip to content

🐛 fix(dom): skip template and foreign base/meta tags - #2231

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/base-meta-template-1685
Nov 16, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/base-meta-template-1685

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

Document.base_url(), Document.meta_refresh() and Node.links() find the document's <base href> and its refresh <meta> by walking every node, template contents included (base walk, refresh walk, link refresh check). A crawler or link checker that resolves links against the base could therefore pick a <base> that a browser never reads, or follow a refresh tag that a browser ignores. Once this merges, these calls return the base and redirect that a browser follows. Fixes #1685.

The HTML standard keeps a <template>'s children in a separate inert document (template element), so the walks now step over template contents. The base and refresh lookups also accept only HTML elements, because a base or meta in the SVG or MathML namespace is not the document's base element. Link extraction applies the same rule to refresh tags and still reports <a href> and other URLs found inside templates, as before.

Callers of the base lookup, including extract_links() and structured_data(), now get the next real base element or the fallback when the only <base href> sits in a template or in SVG or MathML. A refresh tag in those places no longer redirects from meta_refresh(), links(), rewrite_links() or resolve_links().

The change was first merged as #2175 (4e1f30910). The squash merge of #2185 (612eda868) then dropped it from main, and release 1.15.11 shipped without it. This PR re-applies the change on the current main and leaves the XSD changes from #2185 as they are.

Base URL, meta refresh and link extraction walked every node, so a
<base> or <meta http-equiv=refresh> inside <template>, or an SVG or
MathML element named base or meta, could hide the one a browser acts
on or be reported as the redirect. Crawlers and link checkers that
resolve links against the base then used the wrong URL.

The walks now skip template contents, and the base and refresh lookups
accept only HTML elements. Links inside a template are still reported;
only the refresh redirect changes.

PR tox-dev#2175 made this change first, but the squash merge of tox-dev#2185
(612eda8) dropped it from main, so release 1.15.11 shipped without
it. This commit re-applies it on the current main.

Fixes tox-dev#1685
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
@gaborbernat
gaborbernat merged commit 7e6d0f9 into tox-dev:main Nov 16, 2026
57 checks passed
@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 582 untouched benchmarks
⏩ 89 skipped benchmarks1


Comparing gaborbernat:fix/base-meta-template-1685 (dce904b) with main (6c6e490)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat deleted the fix/base-meta-template-1685 branch November 16, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

base_url() takes the <base href> from inside a template, not from the document

1 participant