From cba8b242f5a664ff0c652689ce3dfcd070b3d46d 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 --- test/doctool/test-doctool-html.js | 7 ++++++- test/fixtures/altdocs.md | 3 +++ tools/doc/html.js | 1 + 3 files changed, 10 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..c74d19dfe9f7c6 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
' + '', }, + { + 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..f26c89c89af4ab --- /dev/null +++ b/test/fixtures/altdocs.md @@ -0,0 +1,3 @@ +# 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; }