Skip to content

Commit

Permalink
[css extraction] Ignore empty lines in table definitions (#1469)
Browse files Browse the repository at this point in the history
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 w3c/webref#1130
  • Loading branch information
tidoust authored Jan 26, 2024
1 parent 3f86535 commit 1bd8ccb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/browserlib/extract-cssdfn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/extract-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<table class="propdef">
<tbody>
<tr>
<th>Name:</th>
<td>background-color</td>
</tr>
<tr>
<th><a href="#values">Value</a>:</th>
<td>&lt;color&gt;</td>
</tr>
<tr>
<th></th>
</tr>
</tbody></table>`,
css: [{
"name": "background-color",
"value": "<color>"
}]
}
];

Expand Down

0 comments on commit 1bd8ccb

Please sign in to comment.