@aemforms/af-core 0.22.154 → 0.22.156

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.
@@ -1037,6 +1037,34 @@ const replaceTemplatePlaceholders = (str, values = []) => {
1037
1037
  return typeof replacement !== 'undefined' ? replacement : match;
1038
1038
  });
1039
1039
  };
1040
+ const sanitizeName = (name) => {
1041
+ const nameRegex = /^[A-Za-z0-9_$][A-Za-z0-9_.[\]]*$/;
1042
+ if (name.includes('.')) {
1043
+ const parts = name.split('.');
1044
+ const sanitizedParts = parts.map((part) => {
1045
+ if (part.includes('[')) {
1046
+ const bracketIndex = part.indexOf('[');
1047
+ const namePart = part.substring(0, bracketIndex);
1048
+ const bracketPart = part.substring(bracketIndex);
1049
+ if (!nameRegex.test(namePart)) {
1050
+ return `"${namePart}"${bracketPart}`;
1051
+ }
1052
+ return part;
1053
+ }
1054
+ else {
1055
+ if (!nameRegex.test(part)) {
1056
+ return `"${part}"`;
1057
+ }
1058
+ return part;
1059
+ }
1060
+ });
1061
+ return sanitizedParts.join('.');
1062
+ }
1063
+ if (!nameRegex.test(name)) {
1064
+ return `"${name}"`;
1065
+ }
1066
+ return name;
1067
+ };
1040
1068
 
1041
1069
  const dateRegex = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
1042
1070
  const emailRegex = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
@@ -1936,7 +1964,8 @@ class Scriptable extends BaseNode {
1936
1964
  try {
1937
1965
  let updatedRule = eString;
1938
1966
  if (this.fragment !== '$form') {
1939
- updatedRule = eString.replaceAll('$form', this.fragment);
1967
+ const sanitizedFragment = sanitizeName(this.fragment);
1968
+ updatedRule = eString.replaceAll('$form', sanitizedFragment);
1940
1969
  }
1941
1970
  this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
1942
1971
  }
@@ -1961,7 +1990,8 @@ class Scriptable extends BaseNode {
1961
1990
  try {
1962
1991
  let updatedExpr = x;
1963
1992
  if (this.fragment !== '$form') {
1964
- updatedExpr = x.replaceAll('$form', this.fragment);
1993
+ const sanitizedFragment = sanitizeName(this.fragment);
1994
+ updatedExpr = x.replaceAll('$form', sanitizedFragment);
1965
1995
  }
1966
1996
  return this.ruleEngine.compileRule(updatedExpr, this.lang);
1967
1997
  }
@@ -5,7 +5,7 @@ export * from './utils/TranslationUtils';
5
5
  export * from './utils/JsonUtils';
6
6
  export * from './utils/SchemaUtils';
7
7
  export * from './Constant';
8
- import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments } from './utils/FormUtils';
8
+ import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments, sanitizeName } from './utils/FormUtils';
9
9
  import { BaseNode } from './BaseNode';
10
10
  import Checkbox from './Checkbox';
11
11
  import CheckboxGroup from './CheckboxGroup';
@@ -22,4 +22,4 @@ import Node from './Node';
22
22
  import Scriptable from './Scriptable';
23
23
  import Form from './Form';
24
24
  import { FunctionRuntime, request } from './rules/FunctionRuntime';
25
- export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, readAttachments, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha };
25
+ export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, readAttachments, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha, sanitizeName };
@@ -13,3 +13,4 @@ export declare const dataURItoBlob: (dataURI: string) => {
13
13
  } | null;
14
14
  export declare const sitesModelToFormModel: (sitesModel: any) => any;
15
15
  export declare const replaceTemplatePlaceholders: (str: string, values?: any[]) => string;
16
+ export declare const sanitizeName: (name: string) => string;
package/lib/Scriptable.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const BaseNode_1 = require("./BaseNode");
4
+ const FormUtils_1 = require("./utils/FormUtils");
4
5
  class Scriptable extends BaseNode_1.BaseNode {
5
6
  constructor() {
6
7
  super(...arguments);
@@ -17,7 +18,8 @@ class Scriptable extends BaseNode_1.BaseNode {
17
18
  try {
18
19
  let updatedRule = eString;
19
20
  if (this.fragment !== '$form') {
20
- updatedRule = eString.replaceAll('$form', this.fragment);
21
+ const sanitizedFragment = (0, FormUtils_1.sanitizeName)(this.fragment);
22
+ updatedRule = eString.replaceAll('$form', sanitizedFragment);
21
23
  }
22
24
  this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
23
25
  }
@@ -43,7 +45,8 @@ class Scriptable extends BaseNode_1.BaseNode {
43
45
  try {
44
46
  let updatedExpr = x;
45
47
  if (this.fragment !== '$form') {
46
- updatedExpr = x.replaceAll('$form', this.fragment);
48
+ const sanitizedFragment = (0, FormUtils_1.sanitizeName)(this.fragment);
49
+ updatedExpr = x.replaceAll('$form', sanitizedFragment);
47
50
  }
48
51
  return this.ruleEngine.compileRule(updatedExpr, this.lang);
49
52
  }
package/lib/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export * from './utils/TranslationUtils';
5
5
  export * from './utils/JsonUtils';
6
6
  export * from './utils/SchemaUtils';
7
7
  export * from './Constant';
8
- import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments } from './utils/FormUtils';
8
+ import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments, sanitizeName } from './utils/FormUtils';
9
9
  import { BaseNode } from './BaseNode';
10
10
  import Checkbox from './Checkbox';
11
11
  import CheckboxGroup from './CheckboxGroup';
@@ -22,4 +22,4 @@ import Node from './Node';
22
22
  import Scriptable from './Scriptable';
23
23
  import Form from './Form';
24
24
  import { FunctionRuntime, request } from './rules/FunctionRuntime';
25
- export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, readAttachments, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha };
25
+ export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, readAttachments, FunctionRuntime, request, isEmpty, SubmitMetaData, EmailInput, Captcha, sanitizeName };
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Captcha = exports.EmailInput = exports.SubmitMetaData = exports.isEmpty = exports.request = exports.FunctionRuntime = exports.readAttachments = exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
20
+ exports.sanitizeName = exports.Captcha = exports.EmailInput = exports.SubmitMetaData = exports.isEmpty = exports.request = exports.FunctionRuntime = exports.readAttachments = exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
21
21
  __exportStar(require("./FormInstance"), exports);
22
22
  __exportStar(require("./types/index"), exports);
23
23
  __exportStar(require("./controller/Events"), exports);
@@ -30,6 +30,7 @@ Object.defineProperty(exports, "getFileSizeInBytes", { enumerable: true, get: fu
30
30
  Object.defineProperty(exports, "extractFileInfo", { enumerable: true, get: function () { return FormUtils_1.extractFileInfo; } });
31
31
  Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return FormUtils_1.isEmpty; } });
32
32
  Object.defineProperty(exports, "readAttachments", { enumerable: true, get: function () { return FormUtils_1.readAttachments; } });
33
+ Object.defineProperty(exports, "sanitizeName", { enumerable: true, get: function () { return FormUtils_1.sanitizeName; } });
33
34
  const BaseNode_1 = require("./BaseNode");
34
35
  Object.defineProperty(exports, "BaseNode", { enumerable: true, get: function () { return BaseNode_1.BaseNode; } });
35
36
  const Checkbox_1 = __importDefault(require("./Checkbox"));
@@ -13,3 +13,4 @@ export declare const dataURItoBlob: (dataURI: string) => {
13
13
  } | null;
14
14
  export declare const sitesModelToFormModel: (sitesModel: any) => any;
15
15
  export declare const replaceTemplatePlaceholders: (str: string, values?: any[]) => string;
16
+ export declare const sanitizeName: (name: string) => string;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.replaceTemplatePlaceholders = exports.sitesModelToFormModel = exports.dataURItoBlob = exports.extractFileInfo = exports.isDataUrl = exports.IdGenerator = exports.getFileSizeInBytes = exports.getAttachments = exports.readAttachments = exports.isEmpty = exports.randomWord = void 0;
12
+ exports.sanitizeName = exports.replaceTemplatePlaceholders = exports.sitesModelToFormModel = exports.dataURItoBlob = exports.extractFileInfo = exports.isDataUrl = exports.IdGenerator = exports.getFileSizeInBytes = exports.getAttachments = exports.readAttachments = exports.isEmpty = exports.randomWord = void 0;
13
13
  const JsonUtils_1 = require("./JsonUtils");
14
14
  const FileObject_1 = require("../FileObject");
15
15
  const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
@@ -285,3 +285,32 @@ const replaceTemplatePlaceholders = (str, values = []) => {
285
285
  });
286
286
  };
287
287
  exports.replaceTemplatePlaceholders = replaceTemplatePlaceholders;
288
+ const sanitizeName = (name) => {
289
+ const nameRegex = /^[A-Za-z0-9_$][A-Za-z0-9_.[\]]*$/;
290
+ if (name.includes('.')) {
291
+ const parts = name.split('.');
292
+ const sanitizedParts = parts.map((part) => {
293
+ if (part.includes('[')) {
294
+ const bracketIndex = part.indexOf('[');
295
+ const namePart = part.substring(0, bracketIndex);
296
+ const bracketPart = part.substring(bracketIndex);
297
+ if (!nameRegex.test(namePart)) {
298
+ return `"${namePart}"${bracketPart}`;
299
+ }
300
+ return part;
301
+ }
302
+ else {
303
+ if (!nameRegex.test(part)) {
304
+ return `"${part}"`;
305
+ }
306
+ return part;
307
+ }
308
+ });
309
+ return sanitizedParts.join('.');
310
+ }
311
+ if (!nameRegex.test(name)) {
312
+ return `"${name}"`;
313
+ }
314
+ return name;
315
+ };
316
+ exports.sanitizeName = sanitizeName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.154",
3
+ "version": "0.22.156",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@adobe/json-formula": "0.1.50",
40
- "@aemforms/af-formatters": "^0.22.154"
40
+ "@aemforms/af-formatters": "^0.22.156"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",