Skip to content

Commit

Permalink
Fix regex when only the days have leading zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
r0qs committed Nov 25, 2022
1 parent a7858af commit d156528
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit d156528

Please sign in to comment.