saasufy-components 7.11.0 → 7.12.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/package.json +1 -1
- package/utils.js +15 -13
package/package.json
CHANGED
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
|
|
23
|
+
return toSafeString(value)
|
|
24
|
+
.replace(/&(?!(amp|lt|gt|quot|#039|#123|#125);)/g, '&')
|
|
11
25
|
.replace(/<(?!br ?\/?>)/g, '<')
|
|
12
26
|
.replace(/(?<!br ?\/?)>/g, '>')
|
|
13
27
|
.replace(/"/g, '"')
|
|
@@ -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;
|