Description
In src/core/link-to-dfn.js:326, the scoping hint uses elem.closest("[data-link-for]") to detect if a broken link is inside a data-link-for section.
However, closest() matches the element itself first. When using inline shorthand like [=bar/foo=], the <a> element gets data-link-for="bar" directly on it. The hint then falsely says:
This link is inside a data-link-for="bar" section
...when the attribute is on the link itself, not a parent section.
Additionally, when data-link-for="" (intentionally unscoped), the hint still fires and tells the author to add data-link-for="" — which is already present.
Suggested fix
Use elem.parentElement?.closest("[data-link-for]") to restrict to ancestors only, and guard against the empty-string case:
const scopedSection = elem.parentElement?.closest("[data-link-for]");
const scopingNote = scopedSection?.dataset.linkFor
? ` This link is inside a ...`
: "";
Found by
Adversarial gate holdout test (blind review of PR #5170).
Description
In
src/core/link-to-dfn.js:326, the scoping hint useselem.closest("[data-link-for]")to detect if a broken link is inside adata-link-forsection.However,
closest()matches the element itself first. When using inline shorthand like[=bar/foo=], the<a>element getsdata-link-for="bar"directly on it. The hint then falsely says:...when the attribute is on the link itself, not a parent section.
Additionally, when
data-link-for=""(intentionally unscoped), the hint still fires and tells the author to adddata-link-for=""— which is already present.Suggested fix
Use
elem.parentElement?.closest("[data-link-for]")to restrict to ancestors only, and guard against the empty-string case:Found by
Adversarial gate holdout test (blind review of PR #5170).