ical-generator 11.1.0 → 11.1.1-develop.2

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/package.json CHANGED
@@ -10,21 +10,21 @@
10
10
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
11
11
  "@qiwi/semantic-release-gh-pages-plugin": "^5.4.3",
12
12
  "@sebbo2002/semantic-release-jsr": "^4.0.2",
13
- "@semantic-release/changelog": "^6.0.3",
13
+ "@semantic-release/changelog": "^7.0.0",
14
14
  "@semantic-release/exec": "^7.1.0",
15
- "@semantic-release/git": "^10.0.1",
15
+ "@semantic-release/git": "^11.0.1",
16
16
  "@semantic-release/npm": "^13.1.5",
17
17
  "@touch4it/ical-timezones": "^1.9.0",
18
18
  "@types/express": "^5.0.6",
19
19
  "@types/luxon": "^3.7.2",
20
20
  "@types/mocha": "^10.0.10",
21
21
  "@types/node": "^26.1.1",
22
- "c8": "^11.0.0",
22
+ "c8": "^12.0.0",
23
23
  "dayjs": "^1.11.21",
24
- "eslint": "^10.4.1",
24
+ "eslint": "^10.8.0",
25
25
  "eslint-config-prettier": "^10.1.8",
26
- "eslint-plugin-jsonc": "^3.2.0",
27
- "eslint-plugin-perfectionist": "^5.9.1",
26
+ "eslint-plugin-jsonc": "^3.3.0",
27
+ "eslint-plugin-perfectionist": "^5.10.0",
28
28
  "esm": "^3.2.25",
29
29
  "globals": "^17.7.0",
30
30
  "husky": "^9.1.7",
@@ -33,19 +33,19 @@
33
33
  "mocha": "^11.7.6",
34
34
  "mochawesome": "^7.1.4",
35
35
  "moment": "^2.30.1",
36
- "moment-timezone": "^0.6.2",
36
+ "moment-timezone": "^0.6.3",
37
37
  "nyc": "^18.0.0",
38
- "prettier": "^3.8.4",
38
+ "prettier": "^3.9.6",
39
39
  "rrule": "^2.8.1",
40
- "semantic-release": "^25.0.5",
40
+ "semantic-release": "^25.0.7",
41
41
  "semantic-release-license": "^1.0.2",
42
42
  "source-map-support": "^0.5.21",
43
- "temporal-polyfill": "0.3.2",
44
- "tsdown": "^0.22.2",
45
- "tsx": "^4.22.4",
46
- "typedoc": "^0.28.19",
43
+ "temporal-polyfill": "^1.0.4",
44
+ "tsdown": "^0.22.14",
45
+ "tsx": "^4.23.1",
46
+ "typedoc": "^0.28.20",
47
47
  "typescript": "^6.0.3",
48
- "typescript-eslint": "^8.60.1"
48
+ "typescript-eslint": "^8.65.0"
49
49
  },
50
50
  "engines": {
51
51
  "node": "22 || >=24.0.0"
@@ -141,5 +141,5 @@
141
141
  "test": "mocha"
142
142
  },
143
143
  "type": "module",
144
- "version": "11.1.0"
144
+ "version": "11.1.1-develop.2"
145
145
  }
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
- escape(this.data.attach.mime, false) +
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 += ';SENT-BY="mailto:' + escape(this.data.sentBy, true) + '"';
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 += ';DELEGATED-TO="' + this.data.delegatedTo.email() + '"';
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 += ';DELEGATED-FROM="' + this.data.delegatedFrom.email() + '"';
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="' + escape(this.data.name, true) + '"';
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=' + escape(this.data.email, false);
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() + '=' + escape(value, false),
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
- escape(this.data.location.address, false) +
1767
+ quoteParameterValue(this.data.location.address) +
1766
1768
  ';'
1767
1769
  : '') +
1768
1770
  'X-APPLE-RADIUS=' +
1769
- escape(this.data.location.radius, false) +
1771
+ quoteParameterValue(this.data.location.radius) +
1770
1772
  ';' +
1771
1773
  'X-TITLE=' +
1772
- escape(this.data.location.title, false) +
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
- escape(
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
- escape(
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
- escape(
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="' + escape(this.data.organizer.name, true) + '"';
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
- escape(this.data.organizer.sentBy, true) +
1909
+ escapeParameterValue(this.data.organizer.sentBy) +
1909
1910
  '"';
1910
1911
  }
1911
1912
  if (this.data.organizer.email && this.data.organizer.mailto) {
1912
- g += ';EMAIL=' + escape(this.data.organizer.email, false);
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(inQuotes ? /"/g : /[\\;,]/g, function (match) {
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);