OctopusDeploy / Octostache

| Public | The variable substitution syntax for Octopus Deploy
Other
5 stars 24 forks source link

Make sure unknown variables behave the same as before #84

Closed ghost closed 2 years ago

ghost commented 2 years ago

Background

In release 3.2.0, we enabled filter functions to be used inside condition expressions. When introducing this feature, we inadvertently broke backward compatibility when unknown variables are referenced in the conditionals.

Before introducing the feature (release <= 3.1.0), when evaluating this expression

#{if UnknownVariable}Some words#{/if}

an empty string ("") will be returned as the result if there isn't a variable called UnknownVariable defined. Effectively, unknown variables are treated as empty strings. For this reason, this expression

#{if Unknown1 == Unknown2}Equal!#{/if}

will evaluate to Equal! when both variables are not defined.

In 3.2.0, this behaviour has changed. When a variable is not defined, the evaluation will fail, and the original template will be returned. So, #{if UnknownVariable}Some words#{/if} is no longer able to be processed, and will be treated as a non-template, and returned verbatim.

Result

This PR makes sure that the behaviour in conditional expressions is kept the same as in version 3.1.0 for backward compatibility. Unit tests were also added to document these behaviour.