Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize nightly version string which had leading zeroes #563

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ 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.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) {
st.equal(versionToSemver('0.1.1-6ff4cd6b/RelWithDebInfo-Emscripten/clang/int'), '0.1.1+commit.6ff4cd6b');
st.end();
Expand All @@ -37,6 +43,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
18 changes: 16 additions & 2 deletions translate.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -18,9 +23,18 @@ 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.
// 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];
}
// assume it is already semver compatible
return version;
}
Expand Down