From 7e68f0046ac927806325d68dcf31dc815efeeb8e Mon Sep 17 00:00:00 2001 From: Sebastian Pekarek Date: Tue, 15 Oct 2024 13:00:18 +0200 Subject: [PATCH] fix(Event): Handle location.geo.lat|lon = null close #618 --- src/event.ts | 10 +++++----- test/issues.ts | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/event.ts b/src/event.ts index b058b3651..794e72466 100755 --- a/src/event.ts +++ b/src/event.ts @@ -938,7 +938,7 @@ export default class ICalEvent { } if (location && ( ('title' in location && !location.title) || - (location?.geo && (!isFinite(location.geo.lat) || !isFinite(location.geo.lon))) || + (location?.geo && (typeof location.geo.lat !== 'number' || !isFinite(location.geo.lat) || typeof location.geo.lon !== 'number' || !isFinite(location.geo.lon))) || (!('title' in location) && !location?.geo) )) { throw new Error( @@ -1791,11 +1791,11 @@ export default class ICalEvent { } // GEO - if (this.data.location && 'geo' in this.data.location && this.data.location.geo) { - g += 'GEO:' + escape(this.data.location.geo?.lat, false) + ';' + - escape(this.data.location.geo?.lon, false) + '\r\n'; + if (this.data.location?.geo?.lat && this.data.location.geo.lon) { + g += 'GEO:' + escape(this.data.location.geo.lat, false) + ';' + + escape(this.data.location.geo.lon, false) + '\r\n'; } - + // DESCRIPTION if (this.data.description) { g += 'DESCRIPTION:' + escape(this.data.description.plain, false) + '\r\n'; diff --git a/test/issues.ts b/test/issues.ts index 3acf22607..e344d2dae 100644 --- a/test/issues.ts +++ b/test/issues.ts @@ -324,4 +324,29 @@ describe('Issues', function () { assert.strictEqual(end, '2024-02-29T19:20:00.000Z'); }); }); + + describe('Issue #618', function () { + it('should also produce an error', function () { + assert.throws(() => { + const calendar = ical(); + calendar.createEvent({ + summary: 'Test Event', + start: new Date(), + location: { + title: 'Empty Venue', + + // @ts-ignore + address: null, + geo: { + // @ts-ignore + lat: null, + + // @ts-ignore + lon: null + } + } + }); + }, /`location` isn't formatted correctly/); + }); + }); });