Skip to content

Commit d156528

Browse files
committed
Fix regex when only the days have leading zeros
1 parent a7858af commit d156528

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

test/translate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tape('Version string to Semver translator', function (t) {
2121
t.test('Broken nightly with leading zeroes', function (st) {
2222
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');
2323
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');
24+
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');
2425
st.end();
2526
});
2627
t.test('Old style 0.1.1', function (st) {

translate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function versionToSemver (version) {
3030
return '0.3.5';
3131
}
3232
// This parses the obsolete nightly style where the date can have leading zeroes.
33-
const nightlyParsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-nightly\.([0-9]+)\.0?([1-9])\.0?([1-9])(.*)$/);
33+
// It does not validate the dates, but only if the date format is correct (i.e. YYYY.[M]M.[D]D).
34+
const nightlyParsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-nightly\.([0-9]+)\.0?([1-9]+)\.0?([1-9]+)(.*)$/);
3435
if (nightlyParsed) {
3536
return nightlyParsed[1] + '-nightly.' + nightlyParsed[2] + '.' + nightlyParsed[3] + '.' + nightlyParsed[4] + nightlyParsed[5];
3637
}

0 commit comments

Comments
 (0)