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 <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent bda3311 commit 9564f7a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎tools/doc/common.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ function extractAndParseYAML(text) {
4343
returnmeta;
4444
}
4545

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

‎tools/doc/html.js‎

Lines changed: 11 additions & 3 deletions
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+
constversion=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
returnresult;
327329
}
328330

331+
functionminVersion(a){
332+
returncommon.arrify(a).reduce((min,e)=>{
333+
return!min||versionSort(min,e)<0 ? e : min;
334+
});
335+
}
336+
329337
constnumberRe=/^\d*/;
330338
functionversionSort(a,b){
331-
a=a.trim();
332-
b=b.trim();
339+
a=minVersion(a).trim();
340+
b=minVersion(b).trim();
333341
leti=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)