Expr is an expression language designed to deliver dynamic configurations with unparalleled accuracy,
safety, and speed.
program, err := expr.Compile(`let foo = bar(); baz(foo, foo)`)In this release:
- Security: limit expression nesting depth to prevent a fatal stack overflow on deeply nested input (#1003)
- Security: enforce
MemoryBudgetfor string concatenation and string-producing builtins (#1003) - New feature: added
merge()builtin for combining maps (#947) - New feature: added
log2()builtin (#981) - New feature: support
DisableBuiltin("$env")to hide the$envvariable (#949) - New feature: allow field access on concrete types behind interface values (#952)
- New feature: support optional chaining on slice expressions, e.g.
foo?.[0:1](#945) - Fixed:
DisableBuiltinandDisableAllBuiltinsnow apply to predicate builtins such asall,filterandmap(#1005) - Fixed: compile-time panic on field access after the
filter(...)[0]optimization (#1004) - Fixed: panic in
ConstantNode.Stringon NaN and infinite floats (#974) - Fixed: evaluate the third argument of
reduceandsortByin the enclosing scope (#1002) - Fixed: add
sum([...])elements left to right, matching unoptimized results (#999) - Fixed: resolve embedded-interface fields in
get()(#977) - Fixed: reject pointer-to-map environment with a clear error (#987)
- Fixed: check struct field name is a string in
Fetchandget()(#973) - Fixed: reject non-comparable keys in
fromPairs()(#964) - Fixed: reject negative count in
take()(#965) - Fixed: pop stale bool from stack in
emitLoopBackwards(#954) - Fixed: clear error when fetching a field from a string at runtime (#963)
- Fixed: handle non-comparable
groupBykeys (#940) - Fixed: reject unexported struct fields at runtime (#935)
- Fixed: wrap
LoadLocationerror indate()(#931) - Docs: map literal key types (#998),
WithContextsignature requirements (#997),minandmaxarguments (#985)
Upgrade notes:
- Memory budget: string concatenation and builtins such as
repeat,replace,join,split,toJSONandtoBase64now count againstMemoryBudget. Programs that build very large strings (over about 1 MB with the default budget) may now fail withmemory budget exceeded. Raise the limit withexpr.MemoryBudget(...)if needed. - Custom
Safebuiltins:builtin.Function.Safeandvm.SafeFunctionnow receive the remaining memory budget as their first argument:func(budget uint, args ...any) (any, uint, error). Add a_ uintparameter to existing implementations. DisableAllBuiltins()now also disables predicate builtins (all,any,none,one,filter,map,count,sum,find,findIndex,findLast,findLastIndex,groupBy,sortBy,reduce). Re-enable the ones you need withexpr.EnableBuiltin(...).- Nesting limit: expressions nested more than 10,000 levels deep are rejected at compile time.