-
-
Notifications
You must be signed in to change notification settings - Fork 419
Description
Bug
dfn-index.js crashes with a TypeError when an exported <dfn> element appears in the <section id="abstract"> or any other unnumbered section (introductory sections, SotD, etc.).
Error
Error in handler for topic "toc": Cannot read properties of null (reading 'textContent')
Plugin: sub:toc
In Safari/WebKit the full error is:
null is not an object (evaluating 'document.getElementById(e).closest("section:not(.notoc)").querySelector(".secno").textContent')
Root cause
dfn-index.js:appendSectionNumbers() iterates every term in the local dfn index and tries to read the section number of the section containing each dfn:
const sectionNumberEl = dfn
.closest("section:not(.notoc)")
.querySelector(".secno");
const secNum = `§${sectionNumberEl.textContent.trim()}`; // crashes if .secno is nullThe <section id="abstract"> (and other special/introductory sections) never receive a .secno element because structure.js skips numbering for intro sections. So when a <dfn> in the abstract ends up in the index, .querySelector('.secno') returns null and the next line crashes.
Reproduction
<\!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove" async></script>
<script class="remove">
var respecConfig = { specStatus: "ED", editors: [{ name: "Test" }] };
</script>
</head>
<body>
<section id="abstract">
<p>This spec defines the <dfn>my-concept</dfn>.</p>
</section>
<section id="sotd"></section>
<section id="index"></section>
</body>
</html>Fix
Add a null guard in appendSectionNumbers():
const sectionNumberEl = dfn
.closest("section:not(.notoc)")
?.querySelector(".secno");
if (\!sectionNumberEl) return null; // dfn in unnumbered section — skipA PR with the fix and regression test is on the feat/validate-header-links branch.