feat: support DisableBuiltin("$env") to hide the $env variable#949
Open
boinger wants to merge 1 commit intoexpr-lang:masterfrom
Open
feat: support DisableBuiltin("$env") to hide the $env variable#949boinger wants to merge 1 commit intoexpr-lang:masterfrom
boinger wants to merge 1 commit intoexpr-lang:masterfrom
Conversation
$env is a hardcoded special variable, not a regular builtin, so
DisableBuiltin("$env") previously had no effect. Check config.Disabled
before each $env special-case handler in the checker and compiler.
When disabled, $env falls through to normal identifier resolution
(errors in strict mode as "unknown name $env"), consistent with how
DisableBuiltin works for regular builtins.
Fixes expr-lang#710
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$envis a hardcoded special variable with custom handling in the checker and compiler. It's not in theBuiltinsmap, soDisableBuiltin("$env")previously had no effect.This PR checks
config.Disabled["$env"]before each$envspecial-case handler. When disabled,$envfalls through to normal identifier resolution, which errors in strict mode as"unknown name $env". This is consistent with howDisableBuiltinworks for regular builtins.Changes
checker/checker.go: Guard$envhandling inidentifierNode,memberNode,callNode, andcallBuiltin(theget($env, ...)path) with!v.config.Disabled["$env"]compiler/compiler.go: GuardOpLoadEnvemission inIdentifierNodewith!c.config.Disabled["$env"]test/issues/710/issue_test.go: 7 subtests covering all disabled paths (standalone, member access, call,get()), non-strict mode behavior, and regression tests for default behaviorUse case
Users embedding expr as a DSL may have domain variables that conflict with
$env, or may want to restrict access to the full environment object for sandboxing.Fixes #710