Skip to content

Commit 9564f7a

Browse files
tniessentargos
authored andcommitted
tools: fix doc tool behavior for version arrays
Even though the doc tool supports version arrays in theory, it fails to sort them properly causing the tool to crash. PR-URL: #22766 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bda3311 commit 9564f7a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

tools/doc/common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ function extractAndParseYAML(text) {
4343
return meta;
4444
}
4545

46-
module.exports = { isYAMLBlock, extractAndParseYAML };
46+
module.exports = { arrify, isYAMLBlock, extractAndParseYAML };

tools/doc/html.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ function parseYAML(text) {
308308
.use(htmlStringify)
309309
.processSync(change.description).toString();
310310

311-
result += `<tr><td>${change.version}</td>\n` +
311+
const version = common.arrify(change.version).join(', ');
312+
313+
result += `<tr><td>${version}</td>\n` +
312314
`<td>${description}</td></tr>\n`;
313315
});
314316

@@ -326,10 +328,16 @@ function parseYAML(text) {
326328
return result;
327329
}
328330

331+
function minVersion(a) {
332+
return common.arrify(a).reduce((min, e) => {
333+
return !min || versionSort(min, e) < 0 ? e : min;
334+
});
335+
}
336+
329337
const numberRe = /^\d*/;
330338
function versionSort(a, b) {
331-
a = a.trim();
332-
b = b.trim();
339+
a = minVersion(a).trim();
340+
b = minVersion(b).trim();
333341
let i = 0; // Common prefix length.
334342
while (i < a.length && i < b.length && a[i] === b[i]) i++;
335343
a = a.substr(i);

0 commit comments

Comments
 (0)