File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 4
4
var balanced = require ( "balanced-match" )
5
5
var reduceFunctionCall = require ( "reduce-function-call" )
6
6
7
+ /**
8
+ * Constantes
9
+ */
10
+ var MAX_STACK = 100 // should be enough for a single calc()...
11
+
12
+ /**
13
+ * Global variables
14
+ */
15
+ var stack
16
+
7
17
/**
8
18
* Expose reduceCSSCalc plugin
9
19
*
@@ -17,6 +27,7 @@ module.exports = reduceCSSCalc
17
27
* @param {String } value css input
18
28
*/
19
29
function reduceCSSCalc ( value ) {
30
+ stack = 0
20
31
return reduceFunctionCall ( value , / ( (?: \- [ a - z ] + \- ) ? c a l c ) \( / , evaluateExpression )
21
32
}
22
33
@@ -29,6 +40,11 @@ function reduceCSSCalc(value) {
29
40
*/
30
41
31
42
function evaluateExpression ( expression , functionIdentifier , call ) {
43
+ if ( stack ++ > MAX_STACK ) {
44
+ stack = 0
45
+ throw new Error ( "Call stack overflow for " + call )
46
+ }
47
+
32
48
if ( expression === "" ) {
33
49
throw new Error ( functionIdentifier + "(): '" + call + "' must contain a non-whitespace string" )
34
50
}
You can’t perform that action at this time.
0 commit comments