tbls runs when expressions with the expr package, but first replaces any $ENV_VAR string with the the string, if defined in the environment, with Env.ENV_VAR.
There are two problems with this approach:
If the expression uses the special $expr variable, and the environment variable env exists, then the special variable is replaced by Env.env.
The text replacement can trivially replace text in string literals or other parts of the expression, even though they are not identifiers. E.g. env FOO="bar" BAR='$FOO' tbls --when '$BAR == "$FOO"' should run (BAR is equal to the literal string $FOO), but fails because the string literal "$FOO" in the expression was replaced by "Env.FOO".
The solution is to use ast.Patch() after compiling the expression into an AST to walk, and replacing each $REF name with Env.REF (as a MemberNode with Env identifier and REF string literal). This can be done for all such names (excepting $env) so Env.NONESUCHNAME properly fails as a unknown field NONESUCHNAME error.
tbls runs
when
expressions with theexpr
package, but first replaces any$ENV_VAR
string with the the string, if defined in the environment, withEnv.ENV_VAR
.There are two problems with this approach:
$expr
variable, and the environment variableenv
exists, then the special variable is replaced byEnv.env
.env FOO="bar" BAR='$FOO' tbls --when '$BAR == "$FOO"'
should run (BAR
is equal to the literal string$FOO
), but fails because the string literal"$FOO"
in the expression was replaced by"Env.FOO"
.The solution is to use
ast.Patch()
after compiling the expression into an AST to walk, and replacing each$REF
name withEnv.REF
(as aMemberNode
with Env identifier andREF
string literal). This can be done for all such names (excepting$env
) soEnv.NONESUCHNAME
properly fails as aunknown field NONESUCHNAME
error.I'll create a PR.