Repository navigation
🐛 fix(dom): ignore template and foreign base and meta tags - #2175
Merged
Merged
Conversation
base_url(), meta_refresh(), links() and extract_links() read the document's <base href> or refresh <meta> by walking every node. The walk entered template contents, which belong to an inert document, and it accepted base and meta elements in the SVG and MathML namespaces. An element a browser never acts on could therefore hide the one it does, or be reported as a redirect target, so the base URL used to resolve links was wrong. The walks now step over template contents, and the lookups accept only HTML-namespace elements. The walks stay single passes in document order with no extra allocation.
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Crawlers, link checkers and rewriters resolve relative links against the document's
<base href>and follow its<meta http-equiv=refresh>. 🔗 The lookups behindDocument.base_url(),Document.meta_refresh()andlinks()walked into<template>contents and acceptedbaseandmetaelements in the SVG and MathML namespaces. A browser acts on neither: template children sit in an inert document. An element a browser never acts on could hide the base it uses, or be reported as a redirect that never happens. After this change these APIs return the base and the redirect a browser follows.The lookups skip template contents and accept only HTML-namespace elements. The refresh check in
links()applies the same namespace test asDocument.meta_refresh(), so both report the same redirect. The HTML parser never produces a foreignmeta, so the namespace test matters only for trees rebuilt from pickled data.Behavior changes
<base href>inside a template, or abaseelement in SVG or MathML, no longer sets the base URL. The next real base element applies, or the fallback.links(),rewrite_links(),resolve_links()andextract_links()uses that same base, soextract_links(..., external_only=True)no longer judges links against a<base>inside a template.<meta http-equiv=refresh>inside a template, or in SVG or MathML, no longer redirects.links(),rewrite_links()andresolve_links()report no link for it.links()still reports<a href>and other URLs inside templates. Only the refresh redirect changes.Fixes #1685