@beinformed/ui 1.33.0-beta.6 → 1.33.0
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 +15 -0
- package/esm/models/filters/StringFilterModel.js +10 -3
- package/esm/models/filters/StringFilterModel.js.map +1 -1
- package/esm/utils/helpers/sanitizeHtml.js +4 -9
- package/esm/utils/helpers/sanitizeHtml.js.map +1 -1
- package/lib/models/filters/StringFilterModel.js +10 -3
- package/lib/models/filters/StringFilterModel.js.flow +13 -6
- package/lib/models/filters/StringFilterModel.js.map +1 -1
- package/lib/models/filters/__tests__/ZipcodeFilter.spec.js.flow +17 -1
- package/lib/utils/helpers/__tests__/sanitizeHTML.spec.js.flow +8 -4
- package/lib/utils/helpers/sanitizeHtml.js +4 -10
- package/lib/utils/helpers/sanitizeHtml.js.flow +2 -12
- package/lib/utils/helpers/sanitizeHtml.js.map +1 -1
- package/package.json +2 -2
- package/src/models/filters/StringFilterModel.js +13 -6
- package/src/models/filters/__tests__/ZipcodeFilter.spec.js +17 -1
- package/src/utils/helpers/__tests__/sanitizeHTML.spec.js +8 -4
- package/src/utils/helpers/sanitizeHtml.js +2 -12
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.33.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.7...v1.33.0) (2023-08-29)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **filters:** only handle filter formatting on bsn, iban and zip code with exact and not ([4ebe97c](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/4ebe97c593380a9837460eb1ad9bbf26d1c7e106))
|
|
11
|
+
* **sanitize-html:** handle escaped html ([2e9aa73](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/2e9aa730fb9c48ea69cd7d29419e635b6384c723))
|
|
12
|
+
|
|
13
|
+
## [1.33.0-beta.7](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.6...v1.33.0-beta.7) (2023-08-28)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **validation:** set isvalid to true before update ([d0f2e4f](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/d0f2e4f4b301b90aa86b1ecc512903114649fed4))
|
|
19
|
+
|
|
5
20
|
## [1.33.0-beta.6](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.5...v1.33.0-beta.6) (2023-08-28)
|
|
6
21
|
|
|
7
22
|
|
|
@@ -64,8 +64,9 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
64
64
|
* Update this filter with input name and value
|
|
65
65
|
*/
|
|
66
66
|
update(attribute, value) {
|
|
67
|
+
this._isValid = true;
|
|
67
68
|
this._inputvalue = typeof value !== "string" ? value.toString() : value;
|
|
68
|
-
if (this.
|
|
69
|
+
if (this.shouldHandleFormat()) {
|
|
69
70
|
var _context, _context2;
|
|
70
71
|
const values = this.isMultiple ? _mapInstanceProperty(_context = this._inputvalue.split(",")).call(_context, val => _trimInstanceProperty(val).call(val)) : [_trimInstanceProperty(_context2 = this._inputvalue).call(_context2)];
|
|
71
72
|
const outputValues = [];
|
|
@@ -93,7 +94,7 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
93
94
|
/**
|
|
94
95
|
*/
|
|
95
96
|
formatValue(value) {
|
|
96
|
-
if (this.
|
|
97
|
+
if (this.shouldHandleFormat()) {
|
|
97
98
|
return this.attribute.formatValue(value);
|
|
98
99
|
}
|
|
99
100
|
return value;
|
|
@@ -123,10 +124,16 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
123
124
|
if (value == null || value.toString() === "") {
|
|
124
125
|
return "";
|
|
125
126
|
}
|
|
126
|
-
if (
|
|
127
|
+
if (this.shouldHandleFormat()) {
|
|
127
128
|
return value.replace(/[^a-z0-9,]/gi, "");
|
|
128
129
|
}
|
|
129
130
|
return value;
|
|
130
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
*/
|
|
135
|
+
shouldHandleFormat() {
|
|
136
|
+
return (this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN());
|
|
137
|
+
}
|
|
131
138
|
}
|
|
132
139
|
//# sourceMappingURL=StringFilterModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringFilterModel.js","names":["BaseFilterModel","StringFilterModel","constructor","data","contributions","_defineProperty","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","
|
|
1
|
+
{"version":3,"file":"StringFilterModel.js","names":["BaseFilterModel","StringFilterModel","constructor","data","contributions","_defineProperty","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","shouldHandleFormat","_context","_context2","values","isMultiple","_mapInstanceProperty","split","call","val","_trimInstanceProperty","outputValues","formattedValue","formatValue","push","validate","join","operator","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._isValid = true;\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.shouldHandleFormat()) {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.shouldHandleFormat()) {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (this.shouldHandleFormat()) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n\n /**\n */\n shouldHandleFormat(): boolean {\n return (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n );\n }\n}\n"],"mappings":";;;AACA,OAAOA,eA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A,CAAA,EAAY;IACf,OAAO,IAAI,CAACC,UAAU,CAACC,GAAG,CAAC,KAAK,CAAC;EACnC;;EAEA;AACF;EACEC,MAAMA,CAAA,EAAY;IAChB,OAAO,IAAI,CAACF,UAAU,CAACC,GAAG,CAAC,MAAM,CAAC;EACpC;;EAEA;AACF;EACEE,SAASA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACH,UAAU,CAACC,GAAG,CAAC,SAAS,CAAC;EACvC;;EAEA;AACF;EACE1B,YAAYA,CAACN,KAAc,EAAU;IACnC,IAAIA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACW,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;MAC5C,OAAO,EAAE;IACX;IAEA,IAAI,IAAI,CAACC,kBAAkB,CAAC,CAAC,EAAE;MAC7B,OAAOZ,KAAK,CAACmC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC1C;IAEA,OAAOnC,KAAK;EACd;;EAEA;AACF;EACEY,kBAAkBA,CAAA,EAAY;IAC5B,OACE,CAAC,IAAI,CAACgB,QAAQ,KAAK,SAAS,IAAI,IAAI,CAACA,QAAQ,KAAK,OAAO,MACxD,IAAI,CAACK,MAAM,CAAC,CAAC,IAAI,IAAI,CAACC,SAAS,CAAC,CAAC,IAAI,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC;EAEvD;AACF"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { encode } from "html-entities";
|
|
2
2
|
import { IllegalArgumentException } from "../../exceptions";
|
|
3
3
|
/**
|
|
4
4
|
* Translates html entities to their correct decimal equivalent
|
|
5
5
|
* When path is only one deep better use optional chaining
|
|
6
6
|
*/
|
|
7
7
|
const properEntityEncoding = html => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
return encode(html, {
|
|
9
|
+
mode: "nonAsciiPrintableOnly",
|
|
10
|
+
level: "xml"
|
|
11
11
|
});
|
|
12
|
-
const htmlEncoded = he.encode(htmlDecoded, {
|
|
13
|
-
decimal: true,
|
|
14
|
-
allowUnsafeSymbols: true
|
|
15
|
-
});
|
|
16
|
-
return htmlEncoded;
|
|
17
12
|
};
|
|
18
13
|
|
|
19
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeHtml.js","names":["
|
|
1
|
+
{"version":3,"file":"sanitizeHtml.js","names":["encode","IllegalArgumentException","properEntityEncoding","html","mode","level","removeUnwantedHtml","options","arguments","length","undefined","allowedTags","correctEntityHtml","htmlWithoutAttributes","replace","htmlWithCorrectBR","Array","isArray","join","pattern","regex","RegExp"],"sources":["../../../src/utils/helpers/sanitizeHtml.js"],"sourcesContent":["// @flow\nimport { encode } from \"html-entities\";\n\nimport { IllegalArgumentException } from \"../../exceptions\";\n\ntype removeUnwantedHtmlOptions = {\n allowedTags?: Array<string>,\n};\n\n/**\n * Translates html entities to their correct decimal equivalent\n * When path is only one deep better use optional chaining\n */\nconst properEntityEncoding = (html: string) => {\n return encode(html, { mode: \"nonAsciiPrintableOnly\", level: \"xml\" });\n};\n\n/**\n * removes unwanted html, this might result in incorrect html, as it removes all html that we don't except,\n * like <b style=\"font-weight: 400\">bold</b> will result in bold</b>\n */\nconst removeUnwantedHtml = (\n html: string,\n options: removeUnwantedHtmlOptions = {\n allowedTags: [\"p\", \"br\", \"b\", \"i\", \"u\", \"strike\"],\n },\n): string => {\n if (typeof html !== \"string\") {\n throw new IllegalArgumentException(\"sanitizeHTML method expects a string\");\n }\n\n const correctEntityHtml = properEntityEncoding(html);\n\n // remove attributes from html elements\n const htmlWithoutAttributes = correctEntityHtml.replace(\n /<(\\w+)(.|[\\r\\n])*?>/gi,\n \"<$1>\",\n );\n\n const htmlWithCorrectBR = htmlWithoutAttributes.replace(\n /<br\\s*>/gi,\n \"<br />\",\n );\n\n // remove not allowed tags\n const allowedTags = Array.isArray(options.allowedTags)\n ? options.allowedTags.join(\"|\")\n : \"\";\n const pattern = `<(?!\\\\/?(${allowedTags})(>|\\\\s\\\\/))[^<]+?>`;\n const regex = new RegExp(pattern, \"gi\");\n\n return htmlWithCorrectBR.replace(regex, \"\");\n};\n\nexport { removeUnwantedHtml };\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,eAAe;AAEtC,SAASC,wBAAwB,QAAQ,kBAAkB;AAM3D;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAC7C,OAAOH,MAAM,CAACG,IAAI,EAAE;IAAEC,IAAI,EAAE,uBAAuB;IAAEC,KAAK,EAAE;EAAM,CAAC,CAAC;AACtE,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,SAAAA,CACzBH,IAAY,EAID;EAAA,IAHXI,OAAkC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACnCG,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ;EAClD,CAAC;EAED,IAAI,OAAOR,IAAI,KAAK,QAAQ,EAAE;IAC5B,MAAM,IAAIF,wBAAwB,CAAC,sCAAsC,CAAC;EAC5E;EAEA,MAAMW,iBAAiB,GAAGV,oBAAoB,CAACC,IAAI,CAAC;;EAEpD;EACA,MAAMU,qBAAqB,GAAGD,iBAAiB,CAACE,OAAO,CACrD,uBAAuB,EACvB,MACF,CAAC;EAED,MAAMC,iBAAiB,GAAGF,qBAAqB,CAACC,OAAO,CACrD,WAAW,EACX,QACF,CAAC;;EAED;EACA,MAAMH,WAAW,GAAGK,KAAK,CAACC,OAAO,CAACV,OAAO,CAACI,WAAW,CAAC,GAClDJ,OAAO,CAACI,WAAW,CAACO,IAAI,CAAC,GAAG,CAAC,GAC7B,EAAE;EACN,MAAMC,OAAO,GAAI,YAAWR,WAAY,qBAAoB;EAC5D,MAAMS,KAAK,GAAG,IAAIC,MAAM,CAACF,OAAO,EAAE,IAAI,CAAC;EAEvC,OAAOJ,iBAAiB,CAACD,OAAO,CAACM,KAAK,EAAE,EAAE,CAAC;AAC7C,CAAC;AAED,SAASd,kBAAkB"}
|
|
@@ -71,8 +71,9 @@ class StringFilterModel extends _BaseFilterModel.default {
|
|
|
71
71
|
* Update this filter with input name and value
|
|
72
72
|
*/
|
|
73
73
|
update(attribute, value) {
|
|
74
|
+
this._isValid = true;
|
|
74
75
|
this._inputvalue = typeof value !== "string" ? value.toString() : value;
|
|
75
|
-
if (this.
|
|
76
|
+
if (this.shouldHandleFormat()) {
|
|
76
77
|
var _context, _context2;
|
|
77
78
|
const values = this.isMultiple ? (0, _map.default)(_context = this._inputvalue.split(",")).call(_context, val => (0, _trim.default)(val).call(val)) : [(0, _trim.default)(_context2 = this._inputvalue).call(_context2)];
|
|
78
79
|
const outputValues = [];
|
|
@@ -100,7 +101,7 @@ class StringFilterModel extends _BaseFilterModel.default {
|
|
|
100
101
|
/**
|
|
101
102
|
*/
|
|
102
103
|
formatValue(value) {
|
|
103
|
-
if (this.
|
|
104
|
+
if (this.shouldHandleFormat()) {
|
|
104
105
|
return this.attribute.formatValue(value);
|
|
105
106
|
}
|
|
106
107
|
return value;
|
|
@@ -130,11 +131,17 @@ class StringFilterModel extends _BaseFilterModel.default {
|
|
|
130
131
|
if (value == null || value.toString() === "") {
|
|
131
132
|
return "";
|
|
132
133
|
}
|
|
133
|
-
if (
|
|
134
|
+
if (this.shouldHandleFormat()) {
|
|
134
135
|
return value.replace(/[^a-z0-9,]/gi, "");
|
|
135
136
|
}
|
|
136
137
|
return value;
|
|
137
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
*/
|
|
142
|
+
shouldHandleFormat() {
|
|
143
|
+
return (this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN());
|
|
144
|
+
}
|
|
138
145
|
}
|
|
139
146
|
exports.default = StringFilterModel;
|
|
140
147
|
//# sourceMappingURL=StringFilterModel.js.map
|
|
@@ -71,9 +71,10 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
71
71
|
* Update this filter with input name and value
|
|
72
72
|
*/
|
|
73
73
|
update(attribute: AttributeType, value: string) {
|
|
74
|
+
this._isValid = true;
|
|
74
75
|
this._inputvalue = typeof value !== "string" ? value.toString() : value;
|
|
75
76
|
|
|
76
|
-
if (this.
|
|
77
|
+
if (this.shouldHandleFormat()) {
|
|
77
78
|
const values = this.isMultiple
|
|
78
79
|
? this._inputvalue.split(",").map((val) => val.trim())
|
|
79
80
|
: [this._inputvalue.trim()];
|
|
@@ -105,7 +106,7 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
105
106
|
/**
|
|
106
107
|
*/
|
|
107
108
|
formatValue(value: string): string {
|
|
108
|
-
if (this.
|
|
109
|
+
if (this.shouldHandleFormat()) {
|
|
109
110
|
return this.attribute.formatValue(value);
|
|
110
111
|
}
|
|
111
112
|
return value;
|
|
@@ -136,13 +137,19 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
136
137
|
return "";
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
if (
|
|
140
|
-
(this.operator === "exactly" || this.operator === "isNot") &&
|
|
141
|
-
(this.isIBAN() || this.isZipcode() || this.isBSN())
|
|
142
|
-
) {
|
|
140
|
+
if (this.shouldHandleFormat()) {
|
|
143
141
|
return value.replace(/[^a-z0-9,]/gi, "");
|
|
144
142
|
}
|
|
145
143
|
|
|
146
144
|
return value;
|
|
147
145
|
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
*/
|
|
149
|
+
shouldHandleFormat(): boolean {
|
|
150
|
+
return (
|
|
151
|
+
(this.operator === "exactly" || this.operator === "isNot") &&
|
|
152
|
+
(this.isIBAN() || this.isZipcode() || this.isBSN())
|
|
153
|
+
);
|
|
154
|
+
}
|
|
148
155
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","StringFilterModel","BaseFilterModel","constructor","data","contributions","_defineProperty2","default","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","
|
|
1
|
+
{"version":3,"file":"StringFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","StringFilterModel","BaseFilterModel","constructor","data","contributions","_defineProperty2","default","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","shouldHandleFormat","_context","_context2","values","isMultiple","_map","split","call","val","_trim","outputValues","formattedValue","formatValue","push","validate","join","operator","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace","exports"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._isValid = true;\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.shouldHandleFormat()) {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.shouldHandleFormat()) {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (this.shouldHandleFormat()) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n\n /**\n */\n shouldHandleFormat(): boolean {\n return (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n );\n }\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACe,MAAMC,iBAAiB,SAASC,wBAAe,CAAC;EAK7D;AACF;EACEC,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAC/C,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,oBAPT,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAStB,IAAI,CAACC,MAAM,CAAC,IAAI,CAACC,SAAS,EAAEL,IAAI,CAACM,KAAK,IAAI,EAAE,CAAC;;IAE7C;IACA,IAAI,CAACC,WAAW,GAAG,IAAI,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A,CAACN,KAAc,EAAU;IACnC,IAAIA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACW,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;MAC5C,OAAO,EAAE;IACX;IAEA,IAAI,IAAI,CAACC,kBAAkB,CAAC,CAAC,EAAE;MAC7B,OAAOZ,KAAK,CAACmC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC1C;IAEA,OAAOnC,KAAK;EACd;;EAEA;AACF;EACEY,kBAAkBA,CAAA,EAAY;IAC5B,OACE,CAAC,IAAI,CAACgB,QAAQ,KAAK,SAAS,IAAI,IAAI,CAACA,QAAQ,KAAK,OAAO,MACxD,IAAI,CAACK,MAAM,CAAC,CAAC,IAAI,IAAI,CAACC,SAAS,CAAC,CAAC,IAAI,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC;EAEvD;AACF;AAACM,OAAA,CAAAvC,OAAA,GAAAN,iBAAA"}
|
|
@@ -71,7 +71,10 @@ describe("Zipcode Filter", () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("modular ui input, exact", () => {
|
|
74
|
-
const filter = new StringFilterModel(data,
|
|
74
|
+
const filter = new StringFilterModel(data, {
|
|
75
|
+
...contributions,
|
|
76
|
+
multiplechoice: true,
|
|
77
|
+
});
|
|
75
78
|
|
|
76
79
|
filter.update(filter.attribute, "1234 AB");
|
|
77
80
|
|
|
@@ -86,6 +89,19 @@ describe("Zipcode Filter", () => {
|
|
|
86
89
|
]);
|
|
87
90
|
|
|
88
91
|
expect(filter.isValid).toBe(true);
|
|
92
|
+
|
|
93
|
+
filter.update(filter.attribute, "1234 AB, 2345 CD");
|
|
94
|
+
|
|
95
|
+
expect(filter.isValid).toBe(true);
|
|
96
|
+
|
|
97
|
+
expect(filter.value).toBe("1234 AB,2345 CD");
|
|
98
|
+
expect(filter.inputvalue).toBe("1234 AB, 2345 CD");
|
|
99
|
+
expect(filter.params).toStrictEqual([
|
|
100
|
+
{
|
|
101
|
+
name: "zipfilter",
|
|
102
|
+
value: "1234AB,2345CD",
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
89
105
|
});
|
|
90
106
|
|
|
91
107
|
it("modular ui input, wrong zipcode", () => {
|
|
@@ -29,13 +29,17 @@ describe("sanitizeHTML", () => {
|
|
|
29
29
|
).toBe("<p>String <b>not allowed attribute</b> string</p>");
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
it("
|
|
32
|
+
it("Should keep escaped html", () => {
|
|
33
33
|
expect(
|
|
34
|
-
removeUnwantedHtml(
|
|
35
|
-
|
|
34
|
+
removeUnwantedHtml(
|
|
35
|
+
"<p>Keep <cite>cite tag</cite> and remove <cite>real cite tag</cite>",
|
|
36
|
+
),
|
|
37
|
+
).toBe(
|
|
38
|
+
"<p>Keep <cite>cite tag</cite> and remove real cite tag",
|
|
39
|
+
);
|
|
36
40
|
});
|
|
37
41
|
|
|
38
|
-
it("Can encode special
|
|
42
|
+
it("Can encode special characters to numerical characters", () => {
|
|
39
43
|
expect(removeUnwantedHtml("<p>foo © bar ≠ baz 𝌆 qux bla</p>")).toBe(
|
|
40
44
|
"<p>foo © bar ≠ baz 𝌆 qux bla</p>",
|
|
41
45
|
);
|
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.removeUnwantedHtml = void 0;
|
|
8
|
-
var
|
|
7
|
+
var _htmlEntities = require("html-entities");
|
|
9
8
|
var _exceptions = require("../../exceptions");
|
|
10
9
|
/**
|
|
11
10
|
* Translates html entities to their correct decimal equivalent
|
|
12
11
|
* When path is only one deep better use optional chaining
|
|
13
12
|
*/
|
|
14
13
|
const properEntityEncoding = html => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
return (0, _htmlEntities.encode)(html, {
|
|
15
|
+
mode: "nonAsciiPrintableOnly",
|
|
16
|
+
level: "xml"
|
|
18
17
|
});
|
|
19
|
-
const htmlEncoded = _he.default.encode(htmlDecoded, {
|
|
20
|
-
decimal: true,
|
|
21
|
-
allowUnsafeSymbols: true
|
|
22
|
-
});
|
|
23
|
-
return htmlEncoded;
|
|
24
18
|
};
|
|
25
19
|
|
|
26
20
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import
|
|
2
|
+
import { encode } from "html-entities";
|
|
3
3
|
|
|
4
4
|
import { IllegalArgumentException } from "../../exceptions";
|
|
5
5
|
|
|
@@ -12,17 +12,7 @@ type removeUnwantedHtmlOptions = {
|
|
|
12
12
|
* When path is only one deep better use optional chaining
|
|
13
13
|
*/
|
|
14
14
|
const properEntityEncoding = (html: string) => {
|
|
15
|
-
|
|
16
|
-
decimal: true,
|
|
17
|
-
allowUnsafeSymbols: true,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const htmlEncoded = he.encode(htmlDecoded, {
|
|
21
|
-
decimal: true,
|
|
22
|
-
allowUnsafeSymbols: true,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return htmlEncoded;
|
|
15
|
+
return encode(html, { mode: "nonAsciiPrintableOnly", level: "xml" });
|
|
26
16
|
};
|
|
27
17
|
|
|
28
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeHtml.js","names":["
|
|
1
|
+
{"version":3,"file":"sanitizeHtml.js","names":["_htmlEntities","require","_exceptions","properEntityEncoding","html","encode","mode","level","removeUnwantedHtml","options","arguments","length","undefined","allowedTags","IllegalArgumentException","correctEntityHtml","htmlWithoutAttributes","replace","htmlWithCorrectBR","Array","isArray","join","pattern","regex","RegExp","exports"],"sources":["../../../src/utils/helpers/sanitizeHtml.js"],"sourcesContent":["// @flow\nimport { encode } from \"html-entities\";\n\nimport { IllegalArgumentException } from \"../../exceptions\";\n\ntype removeUnwantedHtmlOptions = {\n allowedTags?: Array<string>,\n};\n\n/**\n * Translates html entities to their correct decimal equivalent\n * When path is only one deep better use optional chaining\n */\nconst properEntityEncoding = (html: string) => {\n return encode(html, { mode: \"nonAsciiPrintableOnly\", level: \"xml\" });\n};\n\n/**\n * removes unwanted html, this might result in incorrect html, as it removes all html that we don't except,\n * like <b style=\"font-weight: 400\">bold</b> will result in bold</b>\n */\nconst removeUnwantedHtml = (\n html: string,\n options: removeUnwantedHtmlOptions = {\n allowedTags: [\"p\", \"br\", \"b\", \"i\", \"u\", \"strike\"],\n },\n): string => {\n if (typeof html !== \"string\") {\n throw new IllegalArgumentException(\"sanitizeHTML method expects a string\");\n }\n\n const correctEntityHtml = properEntityEncoding(html);\n\n // remove attributes from html elements\n const htmlWithoutAttributes = correctEntityHtml.replace(\n /<(\\w+)(.|[\\r\\n])*?>/gi,\n \"<$1>\",\n );\n\n const htmlWithCorrectBR = htmlWithoutAttributes.replace(\n /<br\\s*>/gi,\n \"<br />\",\n );\n\n // remove not allowed tags\n const allowedTags = Array.isArray(options.allowedTags)\n ? options.allowedTags.join(\"|\")\n : \"\";\n const pattern = `<(?!\\\\/?(${allowedTags})(>|\\\\s\\\\/))[^<]+?>`;\n const regex = new RegExp(pattern, \"gi\");\n\n return htmlWithCorrectBR.replace(regex, \"\");\n};\n\nexport { removeUnwantedHtml };\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAMA;AACA;AACA;AACA;AACA,MAAME,oBAAoB,GAAIC,IAAY,IAAK;EAC7C,OAAO,IAAAC,oBAAM,EAACD,IAAI,EAAE;IAAEE,IAAI,EAAE,uBAAuB;IAAEC,KAAK,EAAE;EAAM,CAAC,CAAC;AACtE,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,SAAAA,CACzBJ,IAAY,EAID;EAAA,IAHXK,OAAkC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACnCG,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ;EAClD,CAAC;EAED,IAAI,OAAOT,IAAI,KAAK,QAAQ,EAAE;IAC5B,MAAM,IAAIU,oCAAwB,CAAC,sCAAsC,CAAC;EAC5E;EAEA,MAAMC,iBAAiB,GAAGZ,oBAAoB,CAACC,IAAI,CAAC;;EAEpD;EACA,MAAMY,qBAAqB,GAAGD,iBAAiB,CAACE,OAAO,CACrD,uBAAuB,EACvB,MACF,CAAC;EAED,MAAMC,iBAAiB,GAAGF,qBAAqB,CAACC,OAAO,CACrD,WAAW,EACX,QACF,CAAC;;EAED;EACA,MAAMJ,WAAW,GAAGM,KAAK,CAACC,OAAO,CAACX,OAAO,CAACI,WAAW,CAAC,GAClDJ,OAAO,CAACI,WAAW,CAACQ,IAAI,CAAC,GAAG,CAAC,GAC7B,EAAE;EACN,MAAMC,OAAO,GAAI,YAAWT,WAAY,qBAAoB;EAC5D,MAAMU,KAAK,GAAG,IAAIC,MAAM,CAACF,OAAO,EAAE,IAAI,CAAC;EAEvC,OAAOJ,iBAAiB,CAACD,OAAO,CAACM,KAAK,EAAE,EAAE,CAAC;AAC7C,CAAC;AAACE,OAAA,CAAAjB,kBAAA,GAAAA,kBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.33.0
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"dequal": "^2.0.3",
|
|
90
90
|
"file-size": "^1.0.0",
|
|
91
91
|
"format-message": "^6.2.4",
|
|
92
|
-
"
|
|
92
|
+
"html-entities": "^2.4.0",
|
|
93
93
|
"iban": "^0.0.14",
|
|
94
94
|
"js-cookie": "^3.0.5",
|
|
95
95
|
"klona": "^2.0.6",
|
|
@@ -71,9 +71,10 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
71
71
|
* Update this filter with input name and value
|
|
72
72
|
*/
|
|
73
73
|
update(attribute: AttributeType, value: string) {
|
|
74
|
+
this._isValid = true;
|
|
74
75
|
this._inputvalue = typeof value !== "string" ? value.toString() : value;
|
|
75
76
|
|
|
76
|
-
if (this.
|
|
77
|
+
if (this.shouldHandleFormat()) {
|
|
77
78
|
const values = this.isMultiple
|
|
78
79
|
? this._inputvalue.split(",").map((val) => val.trim())
|
|
79
80
|
: [this._inputvalue.trim()];
|
|
@@ -105,7 +106,7 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
105
106
|
/**
|
|
106
107
|
*/
|
|
107
108
|
formatValue(value: string): string {
|
|
108
|
-
if (this.
|
|
109
|
+
if (this.shouldHandleFormat()) {
|
|
109
110
|
return this.attribute.formatValue(value);
|
|
110
111
|
}
|
|
111
112
|
return value;
|
|
@@ -136,13 +137,19 @@ export default class StringFilterModel extends BaseFilterModel {
|
|
|
136
137
|
return "";
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
if (
|
|
140
|
-
(this.operator === "exactly" || this.operator === "isNot") &&
|
|
141
|
-
(this.isIBAN() || this.isZipcode() || this.isBSN())
|
|
142
|
-
) {
|
|
140
|
+
if (this.shouldHandleFormat()) {
|
|
143
141
|
return value.replace(/[^a-z0-9,]/gi, "");
|
|
144
142
|
}
|
|
145
143
|
|
|
146
144
|
return value;
|
|
147
145
|
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
*/
|
|
149
|
+
shouldHandleFormat(): boolean {
|
|
150
|
+
return (
|
|
151
|
+
(this.operator === "exactly" || this.operator === "isNot") &&
|
|
152
|
+
(this.isIBAN() || this.isZipcode() || this.isBSN())
|
|
153
|
+
);
|
|
154
|
+
}
|
|
148
155
|
}
|
|
@@ -71,7 +71,10 @@ describe("Zipcode Filter", () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("modular ui input, exact", () => {
|
|
74
|
-
const filter = new StringFilterModel(data,
|
|
74
|
+
const filter = new StringFilterModel(data, {
|
|
75
|
+
...contributions,
|
|
76
|
+
multiplechoice: true,
|
|
77
|
+
});
|
|
75
78
|
|
|
76
79
|
filter.update(filter.attribute, "1234 AB");
|
|
77
80
|
|
|
@@ -86,6 +89,19 @@ describe("Zipcode Filter", () => {
|
|
|
86
89
|
]);
|
|
87
90
|
|
|
88
91
|
expect(filter.isValid).toBe(true);
|
|
92
|
+
|
|
93
|
+
filter.update(filter.attribute, "1234 AB, 2345 CD");
|
|
94
|
+
|
|
95
|
+
expect(filter.isValid).toBe(true);
|
|
96
|
+
|
|
97
|
+
expect(filter.value).toBe("1234 AB,2345 CD");
|
|
98
|
+
expect(filter.inputvalue).toBe("1234 AB, 2345 CD");
|
|
99
|
+
expect(filter.params).toStrictEqual([
|
|
100
|
+
{
|
|
101
|
+
name: "zipfilter",
|
|
102
|
+
value: "1234AB,2345CD",
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
89
105
|
});
|
|
90
106
|
|
|
91
107
|
it("modular ui input, wrong zipcode", () => {
|
|
@@ -29,13 +29,17 @@ describe("sanitizeHTML", () => {
|
|
|
29
29
|
).toBe("<p>String <b>not allowed attribute</b> string</p>");
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
it("
|
|
32
|
+
it("Should keep escaped html", () => {
|
|
33
33
|
expect(
|
|
34
|
-
removeUnwantedHtml(
|
|
35
|
-
|
|
34
|
+
removeUnwantedHtml(
|
|
35
|
+
"<p>Keep <cite>cite tag</cite> and remove <cite>real cite tag</cite>",
|
|
36
|
+
),
|
|
37
|
+
).toBe(
|
|
38
|
+
"<p>Keep <cite>cite tag</cite> and remove real cite tag",
|
|
39
|
+
);
|
|
36
40
|
});
|
|
37
41
|
|
|
38
|
-
it("Can encode special
|
|
42
|
+
it("Can encode special characters to numerical characters", () => {
|
|
39
43
|
expect(removeUnwantedHtml("<p>foo © bar ≠ baz 𝌆 qux bla</p>")).toBe(
|
|
40
44
|
"<p>foo © bar ≠ baz 𝌆 qux bla</p>",
|
|
41
45
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import
|
|
2
|
+
import { encode } from "html-entities";
|
|
3
3
|
|
|
4
4
|
import { IllegalArgumentException } from "../../exceptions";
|
|
5
5
|
|
|
@@ -12,17 +12,7 @@ type removeUnwantedHtmlOptions = {
|
|
|
12
12
|
* When path is only one deep better use optional chaining
|
|
13
13
|
*/
|
|
14
14
|
const properEntityEncoding = (html: string) => {
|
|
15
|
-
|
|
16
|
-
decimal: true,
|
|
17
|
-
allowUnsafeSymbols: true,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const htmlEncoded = he.encode(htmlDecoded, {
|
|
21
|
-
decimal: true,
|
|
22
|
-
allowUnsafeSymbols: true,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return htmlEncoded;
|
|
15
|
+
return encode(html, { mode: "nonAsciiPrintableOnly", level: "xml" });
|
|
26
16
|
};
|
|
27
17
|
|
|
28
18
|
/**
|