@contrail/document-generation 1.0.30 → 1.0.32

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.
@@ -5,6 +5,7 @@ const documents_1 = require("@contrail/documents");
5
5
  const interfaces_1 = require("./interfaces");
6
6
  const util_1 = require("@contrail/util");
7
7
  const frame_generator_1 = require("./frame-generator");
8
+ const document_util_1 = require("./util/document-util");
8
9
  class DocumentGenerator {
9
10
  constructor() {
10
11
  }
@@ -79,7 +80,7 @@ class DocumentGenerator {
79
80
  const elements = [];
80
81
  const heading = documents_1.DocumentElementFactory.createTextElement("Placeholder", {});
81
82
  heading.style = { border: { width: 1, color: "rgba(0,0,0,0)" }, color: "#000000", backgroundColor: template.frameGroupHeaderTemplate.style.backgroundColor || 'black' };
82
- heading.text = `<p><span style=\"font-size: ${template.frameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameGroupHeaderTemplate.style.color};\">${dataGroup.name}</span></strong></span></p>`;
83
+ heading.text = `<p><span style=\"font-size: ${template.frameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameGroupHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
83
84
  heading.position = position;
84
85
  if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
85
86
  let sizeDim = template.frameSize.height * span;
@@ -61,7 +61,7 @@ class FrameGenerator {
61
61
  static generateFrameHeaderForDataGroup(dataGroup, position, template, headerSize) {
62
62
  const heading = documents_1.DocumentElementFactory.createTextElement(dataGroup.name, template.frameHeaderTemplate);
63
63
  heading.style = { border: { width: 1, color: "rgba(0,0,0,0)" }, color: "#000000", backgroundColor: template.frameHeaderTemplate.style.backgroundColor || 'black' };
64
- heading.text = `<p><span style=\"font-size: ${template.frameHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameHeaderTemplate.style.color};\">${dataGroup.name}</span></strong></span></p>`;
64
+ heading.text = `<p><span style=\"font-size: ${template.frameHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
65
65
  heading.size = util_1.ObjectUtil.cloneDeep(headerSize);
66
66
  heading.position = util_1.ObjectUtil.cloneDeep(position);
67
67
  return [heading];
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentTextElementUtil = void 0;
4
4
  const documents_1 = require("@contrail/documents");
5
5
  const util_1 = require("@contrail/util");
6
+ const document_util_1 = require("./document-util");
6
7
  class DocumentTextElementUtil {
7
8
  static generateTextElement(textValue, options, applyInlineFormatting = true) {
8
9
  var _a;
@@ -23,7 +24,7 @@ class DocumentTextElementUtil {
23
24
  size.height = size.height || 25;
24
25
  size.width = size.width || 125;
25
26
  const defaultedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { position, size, style });
26
- let element = documents_1.DocumentElementFactory.createTextElement(textValue);
27
+ let element = documents_1.DocumentElementFactory.createTextElement(document_util_1.DocumentUtil.sanitizeHTML(textValue));
27
28
  element = Object.assign(element, defaultedOptions);
28
29
  if (applyInlineFormatting) {
29
30
  element.text = this.applyInLineStyling(element.text, element.style);
@@ -4,4 +4,5 @@ export declare class DocumentUtil {
4
4
  x: number;
5
5
  y: number;
6
6
  };
7
+ static sanitizeHTML(text: string): string;
7
8
  }
@@ -9,5 +9,15 @@ class DocumentUtil {
9
9
  };
10
10
  return relativePosition;
11
11
  }
12
+ static sanitizeHTML(text) {
13
+ if (text === undefined || text === null) {
14
+ return '';
15
+ }
16
+ return text.replace(/&/g, "&amp;")
17
+ .replace(/</g, "&lt;")
18
+ .replace(/>/g, "&gt;")
19
+ .replace(/"/g, "&quot;")
20
+ .replace(/'/g, "&#39;");
21
+ }
12
22
  }
13
23
  exports.DocumentUtil = DocumentUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-generation",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Utilities for automatic generation of documents.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -16,13 +16,13 @@
16
16
  "devDependencies": {
17
17
  "@contrail/aggregates": "^1.0.14",
18
18
  "@contrail/sdk": "^1.2.3",
19
- "@types/jest": "^23.3.14",
19
+ "@types/jest": "^29.5.2",
20
20
  "@types/node": "^18.16.0",
21
- "jest": "^23.6.0",
21
+ "jest": "^29.5.0",
22
22
  "nanoid": "^3.3.6",
23
23
  "npm": "^9.6.5",
24
24
  "prettier": "^1.19.1",
25
- "ts-jest": "^23.10.5",
25
+ "ts-jest": "^29.1.1",
26
26
  "tslint": "^5.11.0",
27
27
  "tslint-config-prettier": "^1.18.0",
28
28
  "typescript": "^4.0.0"