@logicflow/extension 2.1.13 → 2.1.14

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.
@@ -1,3 +1,4 @@
1
1
  declare function handleAttributes(obj: any): any;
2
+ declare function escapeXml(text: string): string;
2
3
  declare function lfJson2Xml(obj: any): string;
3
- export { lfJson2Xml, handleAttributes };
4
+ export { lfJson2Xml, handleAttributes, escapeXml };
@@ -21,6 +21,17 @@ function handleAttributes(obj) {
21
21
  }
22
22
  return obj;
23
23
  }
24
+ function escapeXml(text) {
25
+ if (text == null)
26
+ return '';
27
+ return text
28
+ .toString()
29
+ .replace(/&/g, '&')
30
+ .replace(/</g, '&lt;')
31
+ .replace(/>/g, '&gt;')
32
+ .replace(/"/g, '&quot;')
33
+ .replace(/'/g, '&apos;');
34
+ }
24
35
  function getAttributes(obj) {
25
36
  var tmp = obj;
26
37
  try {
@@ -31,7 +42,7 @@ function getAttributes(obj) {
31
42
  catch (error) {
32
43
  tmp = JSON.stringify(handleAttributes(obj)).replace(/"/g, "'");
33
44
  }
34
- return tmp;
45
+ return escapeXml(String(tmp));
35
46
  }
36
47
  var tn = '\t\n';
37
48
  // @see issue https://github.com/didi/LogicFlow/issues/718, refactoring of function toXml
@@ -42,7 +53,7 @@ function toXml(obj, name, depth) {
42
53
  if (name === '-json')
43
54
  return '';
44
55
  if (name === '#text') {
45
- return prefix + obj;
56
+ return prefix + escapeXml(String(obj));
46
57
  }
47
58
  if (name === '#cdata-section') {
48
59
  return "".concat(prefix, "<![CDATA[").concat(obj, "]]>");
@@ -50,6 +61,9 @@ function toXml(obj, name, depth) {
50
61
  if (name === '#comment') {
51
62
  return "".concat(prefix, "<!--").concat(obj, "-->");
52
63
  }
64
+ if (obj !== 0 && obj !== false && !obj) {
65
+ return "".concat(prefix, "<").concat(name, " />");
66
+ }
53
67
  if ("".concat(name).charAt(0) === '-') {
54
68
  return " ".concat(name.substring(1), "=\"").concat(getAttributes(obj), "\"");
55
69
  }
@@ -70,7 +84,7 @@ function toXml(obj, name, depth) {
70
84
  attributes_1 + (children_1 !== '' ? ">".concat(children_1).concat(prefix, "</").concat(name, ">") : ' />');
71
85
  }
72
86
  else {
73
- str += "".concat(prefix, "<").concat(name, ">").concat(obj.toString(), "</").concat(name, ">");
87
+ str += "".concat(prefix, "<").concat(name, ">").concat(escapeXml(String(obj)), "</").concat(name, ">");
74
88
  }
75
89
  return str;
76
90
  }
@@ -81,4 +95,4 @@ function lfJson2Xml(obj) {
81
95
  }
82
96
  return xmlStr;
83
97
  }
84
- export { lfJson2Xml, handleAttributes };
98
+ export { lfJson2Xml, handleAttributes, escapeXml };
@@ -5,6 +5,7 @@
5
5
  /* eslint-disable func-names */
6
6
  // @ts-nocheck
7
7
  import { has } from 'lodash-es';
8
+ import { escapeXml } from './json2xml';
8
9
  // ========================================================================
9
10
  // XML.ObjTree -- XML source code from/to JavaScript object like E4X
10
11
  // ========================================================================
@@ -295,13 +296,7 @@ XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
295
296
  return "<".concat(name, ">").concat(this.xml_escape(text), "</").concat(name, ">\n");
296
297
  };
297
298
  // method: xml_escape( text )
298
- XML.ObjTree.prototype.xml_escape = function (text) {
299
- return text
300
- .replace(/&/g, '&')
301
- .replace(/</g, '<')
302
- .replace(/>/g, '>')
303
- .replace(/"/g, '"');
304
- };
299
+ XML.ObjTree.prototype.xml_escape = escapeXml;
305
300
  /*
306
301
  // ========================================================================
307
302
 
@@ -1,3 +1,4 @@
1
1
  declare function handleAttributes(obj: any): any;
2
+ declare function escapeXml(text: string): string;
2
3
  declare function lfJson2Xml(obj: any): string;
3
- export { lfJson2Xml, handleAttributes };
4
+ export { lfJson2Xml, handleAttributes, escapeXml };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleAttributes = exports.lfJson2Xml = void 0;
3
+ exports.escapeXml = exports.handleAttributes = exports.lfJson2Xml = void 0;
4
4
  /* eslint-disable guard-for-in */
5
5
  function type(obj) {
6
6
  return Object.prototype.toString.call(obj);
@@ -25,6 +25,18 @@ function handleAttributes(obj) {
25
25
  return obj;
26
26
  }
27
27
  exports.handleAttributes = handleAttributes;
28
+ function escapeXml(text) {
29
+ if (text == null)
30
+ return '';
31
+ return text
32
+ .toString()
33
+ .replace(/&/g, '&amp;')
34
+ .replace(/</g, '&lt;')
35
+ .replace(/>/g, '&gt;')
36
+ .replace(/"/g, '&quot;')
37
+ .replace(/'/g, '&apos;');
38
+ }
39
+ exports.escapeXml = escapeXml;
28
40
  function getAttributes(obj) {
29
41
  var tmp = obj;
30
42
  try {
@@ -35,7 +47,7 @@ function getAttributes(obj) {
35
47
  catch (error) {
36
48
  tmp = JSON.stringify(handleAttributes(obj)).replace(/"/g, "'");
37
49
  }
38
- return tmp;
50
+ return escapeXml(String(tmp));
39
51
  }
40
52
  var tn = '\t\n';
41
53
  // @see issue https://github.com/didi/LogicFlow/issues/718, refactoring of function toXml
@@ -46,7 +58,7 @@ function toXml(obj, name, depth) {
46
58
  if (name === '-json')
47
59
  return '';
48
60
  if (name === '#text') {
49
- return prefix + obj;
61
+ return prefix + escapeXml(String(obj));
50
62
  }
51
63
  if (name === '#cdata-section') {
52
64
  return "".concat(prefix, "<![CDATA[").concat(obj, "]]>");
@@ -54,6 +66,9 @@ function toXml(obj, name, depth) {
54
66
  if (name === '#comment') {
55
67
  return "".concat(prefix, "<!--").concat(obj, "-->");
56
68
  }
69
+ if (obj !== 0 && obj !== false && !obj) {
70
+ return "".concat(prefix, "<").concat(name, " />");
71
+ }
57
72
  if ("".concat(name).charAt(0) === '-') {
58
73
  return " ".concat(name.substring(1), "=\"").concat(getAttributes(obj), "\"");
59
74
  }
@@ -74,7 +89,7 @@ function toXml(obj, name, depth) {
74
89
  attributes_1 + (children_1 !== '' ? ">".concat(children_1).concat(prefix, "</").concat(name, ">") : ' />');
75
90
  }
76
91
  else {
77
- str += "".concat(prefix, "<").concat(name, ">").concat(obj.toString(), "</").concat(name, ">");
92
+ str += "".concat(prefix, "<").concat(name, ">").concat(escapeXml(String(obj)), "</").concat(name, ">");
78
93
  }
79
94
  return str;
80
95
  }
@@ -8,6 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.lfXml2Json = void 0;
10
10
  var lodash_es_1 = require("lodash-es");
11
+ var json2xml_1 = require("./json2xml");
11
12
  // ========================================================================
12
13
  // XML.ObjTree -- XML source code from/to JavaScript object like E4X
13
14
  // ========================================================================
@@ -298,13 +299,7 @@ XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
298
299
  return "<".concat(name, ">").concat(this.xml_escape(text), "</").concat(name, ">\n");
299
300
  };
300
301
  // method: xml_escape( text )
301
- XML.ObjTree.prototype.xml_escape = function (text) {
302
- return text
303
- .replace(/&/g, '&')
304
- .replace(/</g, '<')
305
- .replace(/>/g, '>')
306
- .replace(/"/g, '"');
307
- };
302
+ XML.ObjTree.prototype.xml_escape = json2xml_1.escapeXml;
308
303
  /*
309
304
  // ========================================================================
310
305
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/extension",
3
- "version": "2.1.13",
3
+ "version": "2.1.14",
4
4
  "description": "LogicFlow Extensions",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -24,6 +24,17 @@ function handleAttributes(obj: any): any {
24
24
  return obj
25
25
  }
26
26
 
27
+ function escapeXml(text: string) {
28
+ if (text == null) return ''
29
+ return text
30
+ .toString()
31
+ .replace(/&/g, '&amp;')
32
+ .replace(/</g, '&lt;')
33
+ .replace(/>/g, '&gt;')
34
+ .replace(/"/g, '&quot;')
35
+ .replace(/'/g, '&apos;')
36
+ }
37
+
27
38
  function getAttributes(obj: any) {
28
39
  let tmp = obj
29
40
  try {
@@ -33,7 +44,7 @@ function getAttributes(obj: any) {
33
44
  } catch (error) {
34
45
  tmp = JSON.stringify(handleAttributes(obj)).replace(/"/g, "'")
35
46
  }
36
- return tmp
47
+ return escapeXml(String(tmp))
37
48
  }
38
49
 
39
50
  const tn = '\t\n'
@@ -45,7 +56,7 @@ function toXml(obj: any, name: string, depth: number) {
45
56
  const prefix = tn + frontSpace
46
57
  if (name === '-json') return ''
47
58
  if (name === '#text') {
48
- return prefix + obj
59
+ return prefix + escapeXml(String(obj))
49
60
  }
50
61
  if (name === '#cdata-section') {
51
62
  return `${prefix}<![CDATA[${obj}]]>`
@@ -53,6 +64,9 @@ function toXml(obj: any, name: string, depth: number) {
53
64
  if (name === '#comment') {
54
65
  return `${prefix}<!--${obj}-->`
55
66
  }
67
+ if (obj !== 0 && obj !== false && !obj) {
68
+ return `${prefix}<${name} />`
69
+ }
56
70
  if (`${name}`.charAt(0) === '-') {
57
71
  return ` ${name.substring(1)}="${getAttributes(obj)}"`
58
72
  }
@@ -74,7 +88,7 @@ function toXml(obj: any, name: string, depth: number) {
74
88
  str +=
75
89
  attributes + (children !== '' ? `>${children}${prefix}</${name}>` : ' />')
76
90
  } else {
77
- str += `${prefix}<${name}>${obj.toString()}</${name}>`
91
+ str += `${prefix}<${name}>${escapeXml(String(obj))}</${name}>`
78
92
  }
79
93
 
80
94
  return str
@@ -88,4 +102,4 @@ function lfJson2Xml(obj: any) {
88
102
  return xmlStr
89
103
  }
90
104
 
91
- export { lfJson2Xml, handleAttributes }
105
+ export { lfJson2Xml, handleAttributes, escapeXml }
@@ -6,6 +6,7 @@
6
6
  // @ts-nocheck
7
7
 
8
8
  import { has } from 'lodash-es'
9
+ import { escapeXml } from './json2xml'
9
10
  // ========================================================================
10
11
  // XML.ObjTree -- XML source code from/to JavaScript object like E4X
11
12
  // ========================================================================
@@ -287,14 +288,7 @@ XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
287
288
  }
288
289
 
289
290
  // method: xml_escape( text )
290
-
291
- XML.ObjTree.prototype.xml_escape = function (text) {
292
- return text
293
- .replace(/&/g, '&')
294
- .replace(/</g, '<')
295
- .replace(/>/g, '>')
296
- .replace(/"/g, '"')
297
- }
291
+ XML.ObjTree.prototype.xml_escape = escapeXml
298
292
 
299
293
  /*
300
294
  // ========================================================================