diff --git a/src/event.ts b/src/event.ts index 970098590..c6e852767 100755 --- a/src/event.ts +++ b/src/event.ts @@ -1448,10 +1448,14 @@ export default class ICalEvent { // LOCATION if (this.data.location?.title) { - if (this.data.location.address && this.data.location.radius && this.data.location.geo) { - g += 'LOCATION:' + escape(this.data.location.title + '\n' + this.data.location.address) + '\r\n'; - - g += 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=' + escape(this.data.location.address) + ';' + + if (this.data.location.radius && this.data.location.geo) { + g += 'LOCATION:' + escape( + this.data.location.title + + (this.data.location.address ? '\n' + this.data.location.address : '') + ) + '\r\n'; + + g += 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;' + + (this.data.location.address ? 'X-ADDRESS=' + escape(this.data.location.address) + ';' : '') + 'X-APPLE-RADIUS=' + escape(this.data.location.radius) + ';' + 'X-TITLE=' + escape(this.data.location.title) + ':geo:' + escape(this.data.location.geo?.lat) + ',' + escape(this.data.location.geo?.lon) + '\r\n'; diff --git a/test/issues.ts b/test/issues.ts index 361206a24..a7e0d88f7 100644 --- a/test/issues.ts +++ b/test/issues.ts @@ -142,4 +142,43 @@ describe('Issues', function () { assert.ok(str.indexOf('EXDATE;TZID=America/New_York:20201213T000000') > -1); }); }); + + describe('Issue #236', function () { + it('should look like in the example', function () { + const calendar = ical({ + events: [{ + id: 'foo', + start: new Date('2020-08-13T00:00:00-05:00'), + stamp: new Date('2020-08-13T00:00:00-05:00'), + summary: 'Example Event', + location: { + title: 'Los Angeles, California, United States', + geo: { + lon: -118.24368, + lat: 34.05223, + }, + radius: 400 + } + }] + }); + + assert.strictEqual(calendar.toString(), [ + 'BEGIN:VCALENDAR', + 'VERSION:2.0', + 'PRODID:-//sebbo.net//ical-generator//EN', + 'BEGIN:VEVENT', + 'UID:foo', + 'SEQUENCE:0', + 'DTSTAMP:20200813T050000Z', + 'DTSTART:20200813T050000Z', + 'SUMMARY:Example Event', + 'LOCATION:Los Angeles\\, California\\, United States', + 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-APPLE-RADIUS=400;X-TITLE=Los Angel', + ' es\\, California\\, United States:geo:34.05223,-118.24368', + 'GEO:34.05223;-118.24368', + 'END:VEVENT', + 'END:VCALENDAR' + ].join('\r\n')); + }); + }); });