Skip to content

Commit

Permalink
tools: fix incorrect version history order
Browse files Browse the repository at this point in the history
This fixes an error in parseYAML(text), the version sorting
coudn't be right as we compared an arrify string
(ie. a = ["v18.11, v16.7.0"]) with an array of strings
(ie. b = ["v18.07", "v16.7.0"]) in versionSort(a, b).

minVersion(a) couldn't find the minimum version with an arrify string
like a = ["v18.11, v16.7.0"].
That's why incorrect version history orders sometimes appeared.

Furthermore, no need to sort the added version as it always comes first.
So, it can be the last one to be pushed in the meta.changes array.

Fixes: #45670

Co-authored-by: Luigi Pinca <luigipinca@gmail.com>
PR-URL: #45728
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
2 people authored and juanarbol committed Jan 24, 2023
1 parent 7438ff1 commit e0cda56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions test/doctool/test-doctool-html.mjs
Expand Up @@ -79,10 +79,11 @@ const testData = [
'<div class="api_metadata">' +
'<details class="changelog"><summary>History</summary>' +
'<table><tbody><tr><th>Version</th><th>Changes</th></tr>' +
'<tr><td>v4.2.0</td><td><p>The <code>error</code> parameter can now be' +
'an arrow function.</p></td></tr>' +
'<tr><td>v5.3.0, v4.2.0</td>' +
'<td><p><span>Added in: v5.3.0, v4.2.0</span></p></td></tr>' +
'<tr><td>v4.2.0</td><td><p>The <code>error</code> parameter can now be' +
'an arrow function.</p></td></tr></tbody></table></details></div> ' +
'</tbody></table></details></div> ' +
'<p>Describe <code>Foobar II</code> in more detail here.' +
'<a href="http://man7.org/linux/man-pages/man1/fg.1.html"><code>fg(1)' +
'</code></a></p></section><section>' +
Expand Down
14 changes: 7 additions & 7 deletions tools/doc/html.mjs
Expand Up @@ -325,27 +325,27 @@ function parseYAML(text) {
const removed = { description: '' };

if (meta.added) {
added.version = meta.added.join(', ');
added.description = `<span>Added in: ${added.version}</span>`;
added.version = meta.added;
added.description = `<span>Added in: ${added.version.join(', ')}</span>`;
}

if (meta.deprecated) {
deprecated.version = meta.deprecated.join(', ');
deprecated.version = meta.deprecated;
deprecated.description =
`<span>Deprecated since: ${deprecated.version}</span>`;
`<span>Deprecated since: ${deprecated.version.join(', ')}</span>`;
}

if (meta.removed) {
removed.version = meta.removed.join(', ');
removed.description = `<span>Removed in: ${removed.version}</span>`;
removed.version = meta.removed;
removed.description = `<span>Removed in: ${removed.version.join(', ')}</span>`;
}

if (meta.changes.length > 0) {
if (added.description) meta.changes.push(added);
if (deprecated.description) meta.changes.push(deprecated);
if (removed.description) meta.changes.push(removed);

meta.changes.sort((a, b) => versionSort(a.version, b.version));
if (added.description) meta.changes.push(added);

result += '<details class="changelog"><summary>History</summary>\n' +
'<table>\n<tr><th>Version</th><th>Changes</th></tr>\n';
Expand Down

0 comments on commit e0cda56

Please sign in to comment.