Skip to content

Commit

Permalink
Sanitize nightly version string which had leading zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jan 23, 2022
1 parent 6f8b14c commit 6d804b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions test/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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();
Expand All @@ -36,6 +41,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');
Expand Down
17 changes: 15 additions & 2 deletions translate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const linker = require('./linker.js');

/// 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) {
Expand All @@ -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.
var 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;
}
Expand Down

0 comments on commit 6d804b3

Please sign in to comment.