Skip to content

Commit

Permalink
tools: fix doc tool behavior for version arrays
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tniessen authored and targos committed Sep 19, 2018
1 parent bda3311 commit 9564f7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tools/doc/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ function extractAndParseYAML(text) {
return meta;
}

module.exports = { isYAMLBlock, extractAndParseYAML };
module.exports = { arrify, isYAMLBlock, extractAndParseYAML };
14 changes: 11 additions & 3 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ function parseYAML(text) {
.use(htmlStringify)
.processSync(change.description).toString();

result += `<tr><td>${change.version}</td>\n` +
const version = common.arrify(change.version).join(', ');

result += `<tr><td>${version}</td>\n` +
`<td>${description}</td></tr>\n`;
});

Expand All @@ -326,10 +328,16 @@ function parseYAML(text) {
return result;
}

function minVersion(a) {
return common.arrify(a).reduce((min, e) => {
return !min || versionSort(min, e) < 0 ? e : min;
});
}

const numberRe = /^\d*/;
function versionSort(a, b) {
a = a.trim();
b = b.trim();
a = minVersion(a).trim();
b = minVersion(b).trim();
let i = 0; // Common prefix length.
while (i < a.length && i < b.length && a[i] === b[i]) i++;
a = a.substr(i);
Expand Down

0 comments on commit 9564f7a

Please sign in to comment.