Skip to content

Commit

Permalink
fix(Event): Handle location.geo.lat|lon = null
Browse files Browse the repository at this point in the history
close #618
  • Loading branch information
sebbo2002 committed Oct 15, 2024
1 parent b2e5f64 commit 7e68f00
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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';
Expand Down
25 changes: 25 additions & 0 deletions test/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});
});

0 comments on commit 7e68f00

Please sign in to comment.