@legalplace/wizardx-core 4.12.0 → 4.13.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.
@@ -1,18 +1,15 @@
1
1
  import { componentConnector } from "./connector/componentConnector";
2
2
  import { getRelatedVariablesValues, parseContentWithVariables, } from "../helpers/outputsParsing";
3
- import HtmlSanitizer from "../service/htmlSanitizer";
4
3
  const stateToProps = (selectors) => (state, ownProps) => {
5
4
  const { id, index } = ownProps;
6
5
  const option = selectors.selectOptionReference(id);
7
6
  const boxReference = selectors.selectBoxReference(id);
8
7
  const variables = getRelatedVariablesValues(id, index, boxReference.variables);
9
- const htmlSanitizer = new HtmlSanitizer();
10
8
  const condition = selectors.selectOptionConditionValue(id, index);
11
9
  let content = condition === false
12
10
  ? ""
13
11
  : parseContentWithVariables(boxReference.raw, id, index, variables);
14
12
  content = content.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
15
- content = htmlSanitizer.sanitize(content);
16
13
  const { options, meta } = option;
17
14
  const { tags, type, box } = meta;
18
15
  return {
@@ -1,6 +1,6 @@
1
- import { filterXSS } from "xss";
2
1
  import { selectVariableParents, selectOptionRelations, selectVariableReference, selectOptionReference, selectVariableRelations, areVariablesSiblings, } from "../redux/selectors/references";
3
2
  import { selectVariableInput, selectVariableInputByIndex, } from "../redux/selectors/inputs";
3
+ import HtmlSanitizer from "../service/htmlSanitizer";
4
4
  const frenchNumber = (value) => {
5
5
  let result = typeof value === "number" ? value.toString() : value;
6
6
  if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
@@ -42,17 +42,14 @@ export const parseContentWithVariables = (content, id, index, variables) => {
42
42
  if (Object.prototype.hasOwnProperty.call(contentParsingCache, cacheKey)) {
43
43
  return contentParsingCache[cacheKey];
44
44
  }
45
+ const htmlSanitizer = new HtmlSanitizer();
45
46
  let parsedContent = `${content}`;
46
47
  Object.keys(variables).forEach((variableId) => {
47
48
  let value = variables[variableId].toString();
48
49
  if (value.trim().length === 0) {
49
50
  value = new Array(16).join("_");
50
51
  }
51
- parsedContent = parsedContent.replace(new RegExp(`\\[var:${variableId}\\]`, "gi"), filterXSS(value, {
52
- whiteList: {
53
- a: [],
54
- },
55
- }));
52
+ parsedContent = parsedContent.replace(new RegExp(`\\[var:${variableId}\\]`, "gi"), htmlSanitizer.sanitize(value));
56
53
  });
57
54
  contentParsingCache[cacheKey] = parsedContent;
58
55
  return contentParsingCache[cacheKey];
@@ -0,0 +1,2 @@
1
+ import type { StateType } from "../types/State.type";
2
+ export declare const trimInputs: (inputs: StateType.Inputs) => StateType.Inputs;
@@ -0,0 +1,7 @@
1
+ export const trimInputs = (inputs) => {
2
+ const trimmedVariables = Object.keys(inputs.variables).reduce((acc, key) => {
3
+ acc[key] = inputs.variables[key].map((value) => typeof value === "string" ? value.trim() : value);
4
+ return acc;
5
+ }, {});
6
+ return Object.assign(Object.assign({}, inputs), { variables: trimmedVariables });
7
+ };
@@ -7,6 +7,7 @@ import { selectInputs } from "../selectors/inputs";
7
7
  import { OvcConverter } from "../../libs/OvcConverter";
8
8
  import { updateInstanceArguments } from "../../service/api.manager";
9
9
  import { cancelOnResetState } from "../../helpers/sagaCancelOnResetState";
10
+ import { trimInputs } from "../../helpers/trimInputs";
10
11
  function* saveDataDecorator(action) {
11
12
  try {
12
13
  yield put(setDataStatus("saving"));
@@ -14,7 +15,7 @@ function* saveDataDecorator(action) {
14
15
  const uniqid = selectInstanceUniqid();
15
16
  if (uniqid === undefined)
16
17
  throw new Error("Cannot save data, uniqid is not defined");
17
- const response = yield call(fetch, ...updateInstanceArguments(permalink, uniqid, OvcConverter.convertToOvc(selectInputs()), action.confirmAnswer ? 0 : 1, action.additionalProperties));
18
+ const response = yield call(fetch, ...updateInstanceArguments(permalink, uniqid, OvcConverter.convertToOvc(trimInputs(selectInputs())), action.confirmAnswer ? 0 : 1, action.additionalProperties));
18
19
  const responseData = yield call([response, "json"]);
19
20
  if (action.redirect === true) {
20
21
  const searchParams = new URLSearchParams(window.location.search);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  "@legalplace/model-healthcheck": "^1.1.5",
27
27
  "@legalplace/referencesparser": "^3.1.16",
28
28
  "@legalplace/storybook": "^2.171.0",
29
- "@legalplace/typeorm-constants": "^3.31.0",
29
+ "@legalplace/typeorm-constants": "^3.32.0",
30
30
  "@loadable/component": "^5.15.0",
31
31
  "@redux-saga/core": "^1.1.3",
32
32
  "connected-react-router": "^6.8.0",
@@ -54,11 +54,11 @@
54
54
  "xss": "^1.0.9"
55
55
  },
56
56
  "devDependencies": {
57
- "@legalplace/data-gouv": "^1.5.9",
57
+ "@legalplace/data-gouv": "^1.5.10",
58
58
  "@legalplace/eslint-config": "^2.2.0",
59
- "@legalplace/models-v3-types": "^5.11.3",
59
+ "@legalplace/models-v3-types": "^5.11.4",
60
60
  "@legalplace/prettier-config": "^2.1.3",
61
- "@legalplace/typeorm-entities": "^5.29.5",
61
+ "@legalplace/typeorm-entities": "^5.29.6",
62
62
  "@swc-node/jest": "^1.3.2",
63
63
  "@swc/core": "^1.2.93",
64
64
  "@swc/jest": "^0.2.4",
@@ -96,5 +96,5 @@
96
96
  "*.test.ts",
97
97
  "*.test.tsx"
98
98
  ],
99
- "gitHead": "2093b083375c01f6593ba357465ebded937b7b86"
99
+ "gitHead": "331e8226c0c2a9f66024621240f8485cabe874de"
100
100
  }