k1LoW / tbls

tbls is a CI-Friendly tool for document a database, written in Go.
MIT License
3.32k stars 163 forks source link

when expression parsing too simplistic #599

Closed mjpieters closed 1 week ago

mjpieters commented 1 week ago

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:

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.

I'll create a PR.