From a7858afb72d46d8a2879f33576393ea48ebc045d Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 10 Nov 2021 20:54:59 +0000 Subject: [PATCH 1/2] Sanitize nightly version string which had leading zeroes --- test/translate.ts | 9 +++++++++ translate.ts | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/translate.ts b/test/translate.ts index ecd15231..44697c19 100644 --- a/test/translate.ts +++ b/test/translate.ts @@ -18,6 +18,11 @@ tape('Version string to Semver translator', function (t) { st.equal(versionToSemver('0.4.20-nightly.2018.2.13+commit.27ef9794.Emscripten.clang'), '0.4.20-nightly.2018.2.13+commit.27ef9794.Emscripten.clang'); st.end(); }); + t.test('Broken nightly with leading zeroes', function (st) { + st.equal(versionToSemver('0.3.6-nightly.2016.08.27+commit.91d4fa47.Emscripten.clang'), '0.3.6-nightly.2016.8.27+commit.91d4fa47.Emscripten.clang'); + st.equal(versionToSemver('0.4.1-nightly.2016.09.09+commit.79867f49.Emscripten.clang'), '0.4.1-nightly.2016.9.9+commit.79867f49.Emscripten.clang'); + st.end(); + }); t.test('Old style 0.1.1', function (st) { st.equal(versionToSemver('0.1.1-6ff4cd6b/RelWithDebInfo-Emscripten/clang/int'), '0.1.1+commit.6ff4cd6b'); st.end(); @@ -37,6 +42,10 @@ tape('Version string to Semver translator', function (t) { ); st.end(); }); + t.test('Broken 0.3.4 nightly', function (st) { + st.equal(versionToSemver('0.3.4-0/Release-Emscripten/clang/Interpreter'), '0.3.4-nightly'); + st.end(); + }); t.test('Old style 0.3.5', function (st) { // The one in the solc-bin list st.equal(versionToSemver('0.3.5-371690f0/Release-Emscripten/clang/Interpreter'), '0.3.5+commit.371690f0'); diff --git a/translate.ts b/translate.ts index ca0c39f7..54df9ae0 100644 --- a/translate.ts +++ b/translate.ts @@ -1,15 +1,20 @@ import linker from './linker'; /// Translate old style version numbers to semver. -/// Old style: 0.3.6-3fc68da5/Release-Emscripten/clang +/// Old style: 0.4.1-nightly.2016.09.09+commit.79867f49.Emscripten.clang +/// 0.3.6-nightly.2016.08.27+commit.91d4fa47.Emscripten.clang +/// 0.3.6-3fc68da5/Release-Emscripten/clang /// 0.3.5-371690f0/Release-Emscripten/clang/Interpreter /// 0.3.5-0/Release-Emscripten/clang/Interpreter +/// 0.3.4-0/Release-Emscripten/clang/Interpreter /// 0.2.0-e7098958/.-Emscripten/clang/int linked to libethereum-1.1.1-bbb80ab0/.-Emscripten/clang/int /// 0.1.3-0/.-/clang/int linked to libethereum-0.9.92-0/.-/clang/int /// 0.1.2-5c3bfd4b*/.-/clang/int /// 0.1.1-6ff4cd6b/RelWithDebInfo-Emscripten/clang/int -/// New style: 0.4.5+commit.b318366e.Emscripten.clang +/// New style: 0.8.1-nightly.2021.1.7+commit.d11cf15d.js +/// 0.4.5+commit.b318366e.Emscripten.clang function versionToSemver (version) { + // This parses the old style with a commit hash. It ignores the details past the commit hash. // FIXME: parse more detail, but this is a good start const parsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-([0-9a-f]{8})[/*].*$/); if (parsed) { @@ -18,9 +23,17 @@ function versionToSemver (version) { if (version.indexOf('0.1.3-0') !== -1) { return '0.1.3'; } + if (version.indexOf('0.3.4-0') !== -1) { + return '0.3.4-nightly'; + } if (version.indexOf('0.3.5-0') !== -1) { return '0.3.5'; } + // This parses the obsolete nightly style where the date can have leading zeroes. + const nightlyParsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-nightly\.([0-9]+)\.0?([1-9])\.0?([1-9])(.*)$/); + if (nightlyParsed) { + return nightlyParsed[1] + '-nightly.' + nightlyParsed[2] + '.' + nightlyParsed[3] + '.' + nightlyParsed[4] + nightlyParsed[5]; + } // assume it is already semver compatible return version; } From d156528eb9f093fdcdd5feb1930914463674a691 Mon Sep 17 00:00:00 2001 From: "Rodrigo Q. Saramago" Date: Wed, 28 Sep 2022 11:26:11 +0200 Subject: [PATCH 2/2] Fix regex when only the days have leading zeros --- test/translate.ts | 1 + translate.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/translate.ts b/test/translate.ts index 44697c19..5e8934f4 100644 --- a/test/translate.ts +++ b/test/translate.ts @@ -21,6 +21,7 @@ tape('Version string to Semver translator', function (t) { t.test('Broken nightly with leading zeroes', function (st) { st.equal(versionToSemver('0.3.6-nightly.2016.08.27+commit.91d4fa47.Emscripten.clang'), '0.3.6-nightly.2016.8.27+commit.91d4fa47.Emscripten.clang'); st.equal(versionToSemver('0.4.1-nightly.2016.09.09+commit.79867f49.Emscripten.clang'), '0.4.1-nightly.2016.9.9+commit.79867f49.Emscripten.clang'); + st.equal(versionToSemver('0.4.1-nightly.2016.12.06+commit.79867f49.Emscripten.clang'), '0.4.1-nightly.2016.12.6+commit.79867f49.Emscripten.clang'); st.end(); }); t.test('Old style 0.1.1', function (st) { diff --git a/translate.ts b/translate.ts index 54df9ae0..551817f2 100644 --- a/translate.ts +++ b/translate.ts @@ -30,7 +30,8 @@ function versionToSemver (version) { return '0.3.5'; } // This parses the obsolete nightly style where the date can have leading zeroes. - const nightlyParsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-nightly\.([0-9]+)\.0?([1-9])\.0?([1-9])(.*)$/); + // It does not validate the dates, but only if the date format is correct (i.e. YYYY.[M]M.[D]D). + const nightlyParsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-nightly\.([0-9]+)\.0?([1-9]+)\.0?([1-9]+)(.*)$/); if (nightlyParsed) { return nightlyParsed[1] + '-nightly.' + nightlyParsed[2] + '.' + nightlyParsed[3] + '.' + nightlyParsed[4] + nightlyParsed[5]; }