From 1625329fbfc17fbeeb0932b58cbf24b71927129a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 24 Nov 2018 23:06:55 -0800 Subject: [PATCH] tools,doc: fix version picker bug in html.js The processing of strings like `8.x` into a major version number and a minor version number results in minor versions that are `NaN`. In that situation, since the picker will link to the latest docs in the major version, include the version in the version picker. Fixes: https://github.com/nodejs/node/issues/23979 PR-URL: https://github.com/nodejs/node/pull/24638 Reviewed-By: Vse Mozhet Byt Reviewed-By: Ruben Bridgewater Reviewed-By: Refael Ackermann Reviewed-By: Luigi Pinca Reviewed-By: Franziska Hinkelmann --- test/doctool/test-doctool-html.js | 7 ++++++- test/fixtures/altdocs.md | 2 ++ tools/doc/html.js | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/altdocs.md diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index 499034cd8a3684..703a7dcd21acb0 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -95,6 +95,10 @@ const testData = [ html: '
  1. fish
  2. fish
' + '
  • Red fish
  • Blue fish
', }, + { + file: fixtures.path('altdocs.md'), + html: '
  • 8.x', + }, ]; const spaces = /\s/g; @@ -117,7 +121,8 @@ testData.forEach(({ file, html }) => { const actual = output.replace(spaces, ''); // Assert that the input stripped of all whitespace contains the // expected markup. - assert(actual.includes(expected)); + assert(actual.includes(expected), + `ACTUAL: ${actual}\nEXPECTED: ${expected}`); }) ); })); diff --git a/test/fixtures/altdocs.md b/test/fixtures/altdocs.md new file mode 100644 index 00000000000000..f5320533ad699c --- /dev/null +++ b/test/fixtures/altdocs.md @@ -0,0 +1,2 @@ +# ALTDOCS + diff --git a/tools/doc/html.js b/tools/doc/html.js index 9c9c355574d4e5..ce53bceaa24a15 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -427,6 +427,7 @@ function altDocs(filename, docCreated) { const [versionMajor, versionMinor] = version.num.split('.').map(Number); if (docCreatedMajor > versionMajor) return false; if (docCreatedMajor < versionMajor) return true; + if (Number.isNaN(versionMinor)) return true; return docCreatedMinor <= versionMinor; }