ical-generator 11.1.0-develop.4 → 11.1.1-develop.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +34 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +34 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/alarm.ts +2 -1
- package/src/attendee.ts +19 -6
- package/src/event.ts +13 -12
- package/src/tools.ts +33 -4
package/package.json
CHANGED
package/src/alarm.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
escape,
|
|
11
11
|
formatDate,
|
|
12
12
|
generateCustomAttributes,
|
|
13
|
+
quoteParameterValue,
|
|
13
14
|
toDurationString,
|
|
14
15
|
toJSON,
|
|
15
16
|
} from './tools.ts';
|
|
@@ -518,7 +519,7 @@ export default class ICalAlarm {
|
|
|
518
519
|
) {
|
|
519
520
|
g +=
|
|
520
521
|
'ATTACH;FMTTYPE=' +
|
|
521
|
-
|
|
522
|
+
quoteParameterValue(this.data.attach.mime) +
|
|
522
523
|
':' +
|
|
523
524
|
escape(this.data.attach.uri, false) +
|
|
524
525
|
'\r\n';
|
package/src/attendee.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
checkEnum,
|
|
9
9
|
checkNameAndMail,
|
|
10
10
|
escape,
|
|
11
|
+
escapeParameterValue,
|
|
12
|
+
quoteParameterValue,
|
|
11
13
|
} from './tools.ts';
|
|
12
14
|
|
|
13
15
|
export enum ICalAttendeeRole {
|
|
@@ -543,27 +545,36 @@ export default class ICalAttendee {
|
|
|
543
545
|
|
|
544
546
|
// SENT-BY
|
|
545
547
|
if (this.data.sentBy !== null) {
|
|
546
|
-
g +=
|
|
548
|
+
g +=
|
|
549
|
+
';SENT-BY="mailto:' +
|
|
550
|
+
escapeParameterValue(this.data.sentBy) +
|
|
551
|
+
'"';
|
|
547
552
|
}
|
|
548
553
|
|
|
549
554
|
// DELEGATED-TO
|
|
550
555
|
if (this.data.delegatedTo) {
|
|
551
|
-
g +=
|
|
556
|
+
g +=
|
|
557
|
+
';DELEGATED-TO="' +
|
|
558
|
+
escapeParameterValue(this.data.delegatedTo.email()) +
|
|
559
|
+
'"';
|
|
552
560
|
}
|
|
553
561
|
|
|
554
562
|
// DELEGATED-FROM
|
|
555
563
|
if (this.data.delegatedFrom) {
|
|
556
|
-
g +=
|
|
564
|
+
g +=
|
|
565
|
+
';DELEGATED-FROM="' +
|
|
566
|
+
escapeParameterValue(this.data.delegatedFrom.email()) +
|
|
567
|
+
'"';
|
|
557
568
|
}
|
|
558
569
|
|
|
559
570
|
// CN / Name
|
|
560
571
|
if (this.data.name) {
|
|
561
|
-
g += ';CN="' +
|
|
572
|
+
g += ';CN="' + escapeParameterValue(this.data.name) + '"';
|
|
562
573
|
}
|
|
563
574
|
|
|
564
575
|
// EMAIL
|
|
565
576
|
if (this.data.email && this.data.mailto) {
|
|
566
|
-
g += ';EMAIL=' +
|
|
577
|
+
g += ';EMAIL=' + quoteParameterValue(this.data.email);
|
|
567
578
|
}
|
|
568
579
|
|
|
569
580
|
// SCHEDULE-AGENT
|
|
@@ -578,7 +589,9 @@ export default class ICalAttendee {
|
|
|
578
589
|
this.data.x
|
|
579
590
|
.map(
|
|
580
591
|
([key, value]) =>
|
|
581
|
-
key.toUpperCase() +
|
|
592
|
+
key.toUpperCase() +
|
|
593
|
+
'=' +
|
|
594
|
+
quoteParameterValue(value),
|
|
582
595
|
)
|
|
583
596
|
.join(';');
|
|
584
597
|
}
|
package/src/event.ts
CHANGED
|
@@ -10,10 +10,12 @@ import {
|
|
|
10
10
|
checkEnum,
|
|
11
11
|
checkNameAndMail,
|
|
12
12
|
escape,
|
|
13
|
+
escapeParameterValue,
|
|
13
14
|
formatDate,
|
|
14
15
|
formatDateTZ,
|
|
15
16
|
generateCustomAttributes,
|
|
16
17
|
isRRule,
|
|
18
|
+
quoteParameterValue,
|
|
17
19
|
toDate,
|
|
18
20
|
toDurationString,
|
|
19
21
|
toJSON,
|
|
@@ -1762,14 +1764,14 @@ export default class ICalEvent {
|
|
|
1762
1764
|
'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;' +
|
|
1763
1765
|
(this.data.location.address
|
|
1764
1766
|
? 'X-ADDRESS=' +
|
|
1765
|
-
|
|
1767
|
+
quoteParameterValue(this.data.location.address) +
|
|
1766
1768
|
';'
|
|
1767
1769
|
: '') +
|
|
1768
1770
|
'X-APPLE-RADIUS=' +
|
|
1769
|
-
|
|
1771
|
+
quoteParameterValue(this.data.location.radius) +
|
|
1770
1772
|
';' +
|
|
1771
1773
|
'X-TITLE=' +
|
|
1772
|
-
|
|
1774
|
+
quoteParameterValue(this.data.location.title) +
|
|
1773
1775
|
':geo:' +
|
|
1774
1776
|
escape(this.data.location.geo?.lat, false) +
|
|
1775
1777
|
',' +
|
|
@@ -1819,10 +1821,9 @@ export default class ICalEvent {
|
|
|
1819
1821
|
) {
|
|
1820
1822
|
travelStartParameters.push(
|
|
1821
1823
|
'X-ADDRESS=' +
|
|
1822
|
-
|
|
1824
|
+
quoteParameterValue(
|
|
1823
1825
|
this.data.travelTime.startFrom.location
|
|
1824
1826
|
.address,
|
|
1825
|
-
false,
|
|
1826
1827
|
),
|
|
1827
1828
|
);
|
|
1828
1829
|
}
|
|
@@ -1833,10 +1834,9 @@ export default class ICalEvent {
|
|
|
1833
1834
|
) {
|
|
1834
1835
|
travelStartParameters.push(
|
|
1835
1836
|
'X-APPLE-RADIUS=' +
|
|
1836
|
-
|
|
1837
|
+
quoteParameterValue(
|
|
1837
1838
|
this.data.travelTime.startFrom.location
|
|
1838
1839
|
.radius,
|
|
1839
|
-
false,
|
|
1840
1840
|
),
|
|
1841
1841
|
);
|
|
1842
1842
|
}
|
|
@@ -1847,10 +1847,9 @@ export default class ICalEvent {
|
|
|
1847
1847
|
) {
|
|
1848
1848
|
travelStartParameters.push(
|
|
1849
1849
|
'X-TITLE=' +
|
|
1850
|
-
|
|
1850
|
+
quoteParameterValue(
|
|
1851
1851
|
this.data.travelTime.startFrom.location
|
|
1852
1852
|
.title,
|
|
1853
|
-
false,
|
|
1854
1853
|
),
|
|
1855
1854
|
);
|
|
1856
1855
|
}
|
|
@@ -1900,16 +1899,18 @@ export default class ICalEvent {
|
|
|
1900
1899
|
// ORGANIZER
|
|
1901
1900
|
if (this.data.organizer) {
|
|
1902
1901
|
g +=
|
|
1903
|
-
'ORGANIZER;CN="' +
|
|
1902
|
+
'ORGANIZER;CN="' +
|
|
1903
|
+
escapeParameterValue(this.data.organizer.name) +
|
|
1904
|
+
'"';
|
|
1904
1905
|
|
|
1905
1906
|
if (this.data.organizer.sentBy) {
|
|
1906
1907
|
g +=
|
|
1907
1908
|
';SENT-BY="mailto:' +
|
|
1908
|
-
|
|
1909
|
+
escapeParameterValue(this.data.organizer.sentBy) +
|
|
1909
1910
|
'"';
|
|
1910
1911
|
}
|
|
1911
1912
|
if (this.data.organizer.email && this.data.organizer.mailto) {
|
|
1912
|
-
g += ';EMAIL=' +
|
|
1913
|
+
g += ';EMAIL=' + quoteParameterValue(this.data.organizer.email);
|
|
1913
1914
|
}
|
|
1914
1915
|
|
|
1915
1916
|
g += ':';
|
package/src/tools.ts
CHANGED
|
@@ -206,16 +206,35 @@ export function checkNameAndMail(
|
|
|
206
206
|
return result;
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
|
-
* Escapes special characters in the given string
|
|
209
|
+
* Escapes special characters in the given string. `inQuotes` selects the
|
|
210
|
+
* parameter value encoding (RFC 6868), otherwise the TEXT escaping of
|
|
211
|
+
* RFC 5545 section 3.3.11 is applied.
|
|
210
212
|
*/
|
|
211
213
|
export function escape(str: string | unknown, inQuotes: boolean): string {
|
|
214
|
+
if (inQuotes) {
|
|
215
|
+
return escapeParameterValue(str);
|
|
216
|
+
}
|
|
217
|
+
|
|
212
218
|
return String(str)
|
|
213
|
-
.replace(
|
|
214
|
-
return inQuotes ? '' : '\\' + match;
|
|
215
|
-
})
|
|
219
|
+
.replace(/[\\;,]/g, (match) => '\\' + match)
|
|
216
220
|
.replace(/(?:\r\n|\r|\n)/g, '\\n');
|
|
217
221
|
}
|
|
218
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Encodes a property parameter value as defined by RFC 6868. The backslash
|
|
225
|
+
* escaping used for TEXT values is not defined for parameter values, so the
|
|
226
|
+
* caret encoding is the only way to keep a `"`, a `^` or a line break.
|
|
227
|
+
*/
|
|
228
|
+
export function escapeParameterValue(str: string | unknown): string {
|
|
229
|
+
return (
|
|
230
|
+
String(str)
|
|
231
|
+
// must run first, otherwise the carets introduced below are encoded again
|
|
232
|
+
.replace(/\^/g, '^^')
|
|
233
|
+
.replace(/"/g, "^'")
|
|
234
|
+
.replace(/(?:\r\n|\r|\n)/g, '^n')
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
219
238
|
/**
|
|
220
239
|
* Trim line length of given string
|
|
221
240
|
*/
|
|
@@ -638,6 +657,16 @@ export function isTZDate(value: ICalDateTimeValue): value is ICalTZDateStub {
|
|
|
638
657
|
);
|
|
639
658
|
}
|
|
640
659
|
|
|
660
|
+
/**
|
|
661
|
+
* Encodes a property parameter value (RFC 6868) and wraps it in double quotes
|
|
662
|
+
* if RFC 5545 section 3.2 requires it: `;`, `:` and `,` are not allowed in an
|
|
663
|
+
* unquoted parameter value and would otherwise end the parameter.
|
|
664
|
+
*/
|
|
665
|
+
export function quoteParameterValue(str: string | unknown): string {
|
|
666
|
+
const value = escapeParameterValue(str);
|
|
667
|
+
return /[,:;]/.test(value) ? '"' + value + '"' : value;
|
|
668
|
+
}
|
|
669
|
+
|
|
641
670
|
export function toDate(value: ICalDateTimeValue): Date {
|
|
642
671
|
if (typeof value === 'string' || value instanceof Date) {
|
|
643
672
|
return new Date(value);
|