File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,10 @@ import (
11
11
)
12
12
13
13
var (
14
- // DefaultMemoryBudget represents an upper limit of memory usage
14
+ // DefaultMemoryBudget represents default maximum allowed memory usage by the vm.VM.
15
15
DefaultMemoryBudget uint = 1e6
16
16
17
- // DefaultMaxNodes represents an upper limit of AST nodes
17
+ // DefaultMaxNodes represents default maximum allowed AST nodes by the compiler.
18
18
DefaultMaxNodes uint = 1e4
19
19
)
20
20
Original file line number Diff line number Diff line change @@ -197,6 +197,7 @@ func Timezone(name string) Option {
197
197
198
198
// MaxNodes sets the maximum number of nodes allowed in the expression.
199
199
// By default, the maximum number of nodes is conf.DefaultMaxNodes.
200
+ // If MaxNodes is set to 0, the node budget check is disabled.
200
201
func MaxNodes (n uint ) Option {
201
202
return func (c * conf.Config ) {
202
203
c .MaxNodes = n
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
+ "github.com/expr-lang/expr/conf"
13
14
"github.com/expr-lang/expr/internal/testify/assert"
14
15
"github.com/expr-lang/expr/internal/testify/require"
15
16
"github.com/expr-lang/expr/types"
@@ -2729,6 +2730,16 @@ func TestMaxNodes(t *testing.T) {
2729
2730
require .NoError (t , err )
2730
2731
}
2731
2732
2733
+ func TestMaxNodesDisabled (t * testing.T ) {
2734
+ code := ""
2735
+ for i := 0 ; i < 2 * int (conf .DefaultMaxNodes ); i ++ {
2736
+ code += "1; "
2737
+ }
2738
+
2739
+ _ , err := expr .Compile (code , expr .MaxNodes (0 ))
2740
+ require .NoError (t , err )
2741
+ }
2742
+
2732
2743
func TestMemoryBudget (t * testing.T ) {
2733
2744
tests := []struct {
2734
2745
code string
You can’t perform that action at this time.
0 commit comments