1
|
|
|
import Handlebars from 'handlebars' |
2
|
|
|
import abeEngine from './abeEngine' |
3
|
|
|
import xss from 'xss' |
4
|
|
|
|
5
|
|
|
import { |
6
|
|
|
config |
7
|
|
|
} from '../../../' |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Abe handlebar helper, that retrieve text to add to handlebars templating engine |
11
|
|
|
* @return {String} the string to replace {{ handlebars_key }} |
12
|
|
|
*/ |
13
|
|
|
export default function compileAbe(){ |
14
|
|
|
var content = abeEngine.instance.content |
15
|
|
|
if(typeof arguments[0].hash['key'] === 'undefined' || arguments[0].hash['key'] === null) return '' |
|
|
|
|
16
|
|
|
var key |
17
|
|
|
var hash |
18
|
|
|
var value |
19
|
|
|
var testXSS |
20
|
|
|
if(arguments[0].hash['key'].indexOf('}-') > 0){ |
21
|
|
|
key = arguments[0].hash['key'].split('-') |
22
|
|
|
key = key[key.length - 1] |
23
|
|
|
hash = arguments[0].hash |
24
|
|
|
hash.key = hash.key.replace(/\{\{@index\}\}/, '[{{@index}}]') |
25
|
|
|
try{ |
26
|
|
|
value = content ? content[hash['dictionnary']][arguments[0].data.index][key] : hash.key |
27
|
|
|
} |
28
|
|
|
catch(e){ |
29
|
|
|
value = '' |
30
|
|
|
} |
31
|
|
|
if(typeof value === 'undefined' || typeof value === 'function' || value === null) { |
32
|
|
|
value = '' |
33
|
|
|
} |
34
|
|
|
if(typeof hash.type !== 'undefined' && hash.type !== null && hash.type === 'rich'){ |
35
|
|
|
testXSS = xss(value.replace(/"/g, '"'), { |
36
|
|
|
'whiteList': config.htmlWhiteList, |
37
|
|
|
stripIgnoreTag: true |
38
|
|
|
}) |
39
|
|
|
return new Handlebars.SafeString(testXSS) |
40
|
|
|
} |
41
|
|
|
return value.replace(/%27/, '\'') |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
key = arguments[0].hash['key'].replace('.', '-') |
45
|
|
|
|
46
|
|
|
var hash = arguments[0].hash |
|
|
|
|
47
|
|
|
var value = ((content) ? content[hash.key.replace('.', '-')] : hash.key) |
|
|
|
|
48
|
|
|
if(typeof value === 'undefined' || typeof value === 'function' || value === null) { |
49
|
|
|
value = '' |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if(typeof hash.type !== 'undefined' && hash.type !== null && hash.type === 'rich'){ |
53
|
|
|
testXSS = xss(value.replace(/"/g, '"'), { |
54
|
|
|
'whiteList': config.htmlWhiteList, |
55
|
|
|
stripIgnoreTag: true |
56
|
|
|
}) |
57
|
|
|
return new Handlebars.SafeString(testXSS) |
58
|
|
|
} |
59
|
|
|
return value.replace(/%27/, '\'') |
60
|
|
|
} |
61
|
|
|
|
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.