From 1bd8ccbe097fbcfe835e3785f7f77a98d685a1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Daoust?= Date: Fri, 26 Jan 2024 11:59:18 +0100 Subject: [PATCH] [css extraction] Ignore empty lines in table definitions (#1469) I cannot reproduce it, but Bikeshed generated an empty line at the end of the table definition of `font-style` in css-fonts-4. The extraction logic did not expect that and crashed. This update makes the extraction logic more resilient by ignoring empty lines. Via https://github.com/w3c/webref/issues/1130 --- src/browserlib/extract-cssdfn.mjs | 18 +++++++++++++----- tests/extract-css.js | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/browserlib/extract-cssdfn.mjs b/src/browserlib/extract-cssdfn.mjs index 5a63b3c9..c7c559d3 100644 --- a/src/browserlib/extract-cssdfn.mjs +++ b/src/browserlib/extract-cssdfn.mjs @@ -364,11 +364,19 @@ const extractTableDfn = table => { const cleanedLine = line.cloneNode(true); const annotations = cleanedLine.querySelectorAll(asideSelector); annotations.forEach(n => n.remove()); - return { - name: dfnLabel2Property(cleanedLine.querySelector(':first-child').textContent), - value: normalize(cleanedLine.querySelector('td:last-child').textContent) - }; - }); + const nameEl = cleanedLine.querySelector(':first-child'); + const valueEl = cleanedLine.querySelector('td:last-child'); + if (nameEl && valueEl) { + return { + name: dfnLabel2Property(nameEl.textContent), + value: normalize(valueEl.textContent) + }; + } + else { + return null; + } + }) + .filter(line => !!line); for (let prop of lines) { res[prop.name] = prop.value; } diff --git a/tests/extract-css.js b/tests/extract-css.js index aa2e189d..df726feb 100644 --- a/tests/extract-css.js +++ b/tests/extract-css.js @@ -1484,6 +1484,28 @@ that spans multiple lines */ type: 'type', prose: 'Determines the gradient center of the gradient.' }] + }, + + { + title: 'ignores empty lines in table definitions', + html: ` + + + + + + + + + + + + +
Name:background-color
Value:<color>
`, + css: [{ + "name": "background-color", + "value": "" + }] } ];