ti2-tourplan 1.0.119 → 1.0.121

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-tourplan",
3
- "version": "1.0.119",
3
+ "version": "1.0.121",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -55,13 +55,14 @@ const escapeInvalidXmlChars = str => {
55
55
  ['æ', 'ae'],
56
56
  ['ß', 'ss'],
57
57
  ];
58
- const preprocessed = accentedChars.reduce((acc, [k, v]) => acc.replace(k, v), s);
58
+ const preprocessed = accentedChars.reduce((acc, [k, v]) => acc.split(k).join(v), s);
59
59
  return preprocessed.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
60
60
  };
61
61
  // NOTE: There is no need to sanitize the string for 5 characters (&, <, >, " and ')
62
62
  // because js2xmlparser does that for us. Plus if we use sanitize before calling js2xmlparser
63
63
  // js2xmlparser will escape & to '&amp;' making it invalid XML
64
64
  return convertAccentedChars(asString)
65
+ .replace(/\u00A0/g, ' ')
65
66
  .replace(/’/g, "'")
66
67
  .replace(/‘/g, "'")
67
68
  .replace(/“/g, '"')
package/utils.test.js ADDED
@@ -0,0 +1,36 @@
1
+ const { escapeInvalidXmlChars } = require('./utils');
2
+
3
+ describe('escapeInvalidXmlChars', () => {
4
+ it('returns empty string for falsy input', () => {
5
+ expect(escapeInvalidXmlChars('')).toBe('');
6
+ expect(escapeInvalidXmlChars(null)).toBe('');
7
+ expect(escapeInvalidXmlChars(undefined)).toBe('');
8
+ });
9
+
10
+ it('maps accented letters before NFD stripping', () => {
11
+ expect(escapeInvalidXmlChars('Müller')).toBe('Mueller');
12
+ expect(escapeInvalidXmlChars('Straße')).toBe('Strasse');
13
+ expect(escapeInvalidXmlChars('Søren')).toBe('Soeren');
14
+ });
15
+
16
+ it('maps repeated accented letters for every occurrence', () => {
17
+ expect(escapeInvalidXmlChars('öffnen und rösten')).toBe('oeffnen und roesten');
18
+ expect(escapeInvalidXmlChars('für süße Grüße')).toBe('fuer suesse Gruesse');
19
+ });
20
+
21
+ it('replaces smart quotes and en dash', () => {
22
+ expect(escapeInvalidXmlChars('Say ‘hi’ and “bye” – ok')).toBe('Say \'hi\' and "bye" - ok');
23
+ });
24
+
25
+ it('replaces non-breaking spaces with regular spaces', () => {
26
+ expect(escapeInvalidXmlChars('Borwieck\u00A0Mrs R')).toBe('Borwieck Mrs R');
27
+ });
28
+
29
+ it('strips disallowed control characters', () => {
30
+ expect(escapeInvalidXmlChars('A\u0000B\u0008C')).toBe('ABC');
31
+ });
32
+
33
+ it('strips lone UTF-16 surrogate code units', () => {
34
+ expect(escapeInvalidXmlChars('X\uD800Y')).toBe('XY');
35
+ });
36
+ });