Generated variable values can have spaces or escape sequences in them which would trigger unexpected behavior. For example, consider a command line template such as
echo hello {{name}}
The name variable could expand to a value such as >name, which would inadvertently redirect stdout to name.
We need a quote filter in Jinja2 that calls shlex.quote on the variable. In the above example, the proper solution would be to :
echo hello {{name | quote}}
which would result in a cleaned up value passed into the command line as echo hello '>name' and would be handled correctly.
Generated variable values can have spaces or escape sequences in them which would trigger unexpected behavior. For example, consider a command line template such as
The name variable could expand to a value such as
>name
, which would inadvertently redirect stdout toname
.We need a quote filter in Jinja2 that calls
shlex.quote
on the variable. In the above example, the proper solution would be to :which would result in a cleaned up value passed into the command line as
echo hello '>name'
and would be handled correctly.