ical-generator 1.15.3 → 1.15.4

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/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ _The following document documents changes to this library. Changes to the depend
4
4
 
5
5
  <br />
6
6
 
7
+ ## [1.15.4](https://github.com/sebbo2002/ical-generator/releases/tag/1.15.4) - 2021-01-14
8
+ ### Budgfix
9
+ - Fix: Line folding breaks surrogate pairs ([#221](https://github.com/sebbo2002/ical-generator/issues/221))
10
+
7
11
  ## [1.15.2](https://github.com/sebbo2002/ical-generator/releases/tag/1.15.2) - 2020-11-12
8
12
  ### Bugfix
9
13
  - Types: Add rsvp to AttendeeData
package/dist/_tools.js CHANGED
@@ -122,7 +122,28 @@ var ICalTools = /*#__PURE__*/function () {
122
122
  key: "foldLines",
123
123
  value: function foldLines(input) {
124
124
  return input.split('\r\n').map(function (line) {
125
- return line.match(/(.{1,74})/g).join('\r\n ');
125
+ var result = '';
126
+ var c = 0;
127
+
128
+ for (var i = 0; i < line.length; i++) {
129
+ var ch = line.charAt(i); // surrogate pair, see https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
130
+
131
+ if (ch >= "\uD800" && ch <= "\uDBFF") {
132
+ ch += line.charAt(++i);
133
+ }
134
+
135
+ var charsize = Buffer.from(ch).length;
136
+ c += charsize;
137
+
138
+ if (c > 74) {
139
+ result += '\r\n ';
140
+ c = charsize;
141
+ }
142
+
143
+ result += ch;
144
+ }
145
+
146
+ return result;
126
147
  }).join('\r\n');
127
148
  }
128
149
  }, {
package/package.json CHANGED
@@ -55,5 +55,5 @@
55
55
  },
56
56
  "typings": "index.d.ts",
57
57
  "runkitExampleFilename": "examples/example-runkit.js",
58
- "version": "1.15.3"
58
+ "version": "1.15.4"
59
59
  }
package/src/_tools.js CHANGED
@@ -90,7 +90,26 @@ class ICalTools {
90
90
 
91
91
  static foldLines (input) {
92
92
  return input.split('\r\n').map(function (line) {
93
- return line.match(/(.{1,74})/g).join('\r\n ');
93
+ let result = '';
94
+ let c = 0;
95
+ for (let i = 0; i < line.length; i++) {
96
+ let ch = line.charAt(i);
97
+
98
+ // surrogate pair, see https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
99
+ if (ch >= '\ud800' && ch <= '\udbff') {
100
+ ch += line.charAt(++i);
101
+ }
102
+
103
+ const charsize = Buffer.from(ch).length;
104
+ c += charsize;
105
+ if (c > 74) {
106
+ result += '\r\n ';
107
+ c = charsize;
108
+ }
109
+
110
+ result += ch;
111
+ }
112
+ return result;
94
113
  }).join('\r\n');
95
114
  }
96
115
 
@@ -202,5 +202,11 @@ describe('ICalTools', function () {
202
202
  '12345678ikjhgztrde546rf7g8hjiomkjnhgqfcdxerdftgzuinjhgcfvtzvzvuwcbiweciujz\r\n vguhbghbbqwxowidoi21e8981'
203
203
  );
204
204
  });
205
+ it('should not split surrogate pairs', function () {
206
+ assert.strictEqual(
207
+ ICalTools.foldLines('👋🏼12345678ikjhgztrde546rf7g8hjiomkjnhgqfcdxerdftgzuinjhgcfvtzvzvuwcbiweciujvguhbghbbqwxowidoi21e8981'),
208
+ '👋🏼12345678ikjhgztrde546rf7g8hjiomkjnhgqfcdxerdftgzuinjhgcfvtzvzvuwcb\r\n iweciujvguhbghbbqwxowidoi21e8981'
209
+ );
210
+ });
205
211
  });
206
212
  });