saasufy-components 7.11.0 → 7.12.1

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/utils.js +15 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "7.11.0",
3
+ "version": "7.12.1",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "author": "Jonathan Gros-Dubois",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "ag-collection": "^5.3.1",
20
+ "ag-collection": "^5.3.2",
21
21
  "ag-model": "^3.1.0",
22
22
  "capitalisk-auth-client": "^1.5.1",
23
23
  "socketcluster-client": "^19.2.3",
package/utils.js CHANGED
@@ -5,9 +5,23 @@ import { sha256 } from './sha256.js';
5
5
 
6
6
  const DEFAULT_DEBOUNCE_DELAY = 300;
7
7
  const DEFAULT_RELOAD_DELAY = 0;
8
+
9
+ let expressionCharsRegExp = /\$\{(.*?)\}/g;
10
+ let backtickRegExp = /`/g;
11
+ let templateMultiStartBracesRegExp = /{{{*/g
12
+ let templateMultiEndBracesRegExp = /}}}*/g
13
+
14
+ export function toSafeString(value) {
15
+ return value.replace(expressionCharsRegExp, '$!{$1}')
16
+ .replace(backtickRegExp, `'`)
17
+ .replace(templateMultiStartBracesRegExp, '[[')
18
+ .replace(templateMultiEndBracesRegExp, ']]');
19
+ }
20
+
8
21
  export function toSafeHTML(value) {
9
22
  if (typeof value === 'string') {
10
- return value.replace(/&(?!(amp|lt|gt|quot|#039|#123|#125);)/g, '&')
23
+ return toSafeString(value)
24
+ .replace(/&(?!(amp|lt|gt|quot|#039|#123|#125);)/g, '&')
11
25
  .replace(/<(?!br ?\/?>)/g, '&lt;')
12
26
  .replace(/(?<!br ?\/?)>/g, '&gt;')
13
27
  .replace(/"/g, '&quot;')
@@ -296,9 +310,6 @@ function replaceExpressions(string, replaceFn) {
296
310
  return charList.join('');
297
311
  }
298
312
 
299
- let templateMultiStartBracesRegExp = /{{{*/g
300
- let templateMultiEndBracesRegExp = /}}}*/g
301
-
302
313
  export function renderTemplate(templateString, data, socket, autoExecFunction) {
303
314
  let options = getRenderOptions(data, socket);
304
315
  return replaceExpressions(templateString, (expression) => {
@@ -333,15 +344,6 @@ export function renderTemplate(templateString, data, socket, autoExecFunction) {
333
344
  }
334
345
  result = result();
335
346
  }
336
- if (typeof result === 'string') {
337
- // Double braces cannot contain sub-expressions as it
338
- // would present an XSS vulnerability.
339
- // Replace them with square braces so that any code inside
340
- // will not be executed if output is re-processed later.
341
- result = result
342
- .replace(templateMultiStartBracesRegExp, '[[')
343
- .replace(templateMultiEndBracesRegExp, ']]');
344
- }
345
347
  return toSafeHTML(result);
346
348
  } catch (error) {
347
349
  return expression;