From fb9de61e86b6e3bc67300f3f644a70fa74b323d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 12 Jun 2024 15:19:15 -0700 Subject: [PATCH] Avoid propagating invalid date --- modules/util/date.js | 3 +++ test/spec/util/date.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/modules/util/date.js b/modules/util/date.js index cc04862694..4115731553 100644 --- a/modules/util/date.js +++ b/modules/util/date.js @@ -70,6 +70,9 @@ export function utilNormalizeDateString(raw) { date.setUTCFullYear(parseInt((match[1] || '') + match[2], 10)); if (match[3]) date.setUTCMonth(parseInt(match[3], 10) - 1); // 0-based if (match[4]) date.setUTCDate(parseInt(match[4], 10)); + if (isNaN(date.getDate())) { + return null; + } } else { // Fall back on whatever the browser can parse into a date. date = new Date(raw); diff --git a/test/spec/util/date.js b/test/spec/util/date.js index 2e654de3ac..d2d9d8a2d2 100644 --- a/test/spec/util/date.js +++ b/test/spec/util/date.js @@ -55,6 +55,8 @@ describe('iD.date', function() { it('rejects malformed dates', function() { expect(iD.utilNormalizeDateString('1970-01--1')).to.eql(null); expect(iD.utilNormalizeDateString('197X')).to.eql(null); // no EDTF for now + // https://github.com/OpenHistoricalMap/issues/issues/826 + expect(iD.utilNormalizeDateString('1912091095')).to.eql(null); }); it('respects the original precision', function() { expect(iD.utilNormalizeDateString('123').value).to.eql('0123');