vars: Make nil values act as empty string instead of "<nil>"
#6174
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.
This is a silly little bug.
I was looking into a possible config to fix an issue for Authelia, and while testing I noticed that
vars
andvars_regexp
matchers were turning placeholders that return no value (nil
) into literally the string"<nil>"
because of thedefault:
case doingfmt.Sprintf("%v", vv)
.This means that it was impossible to match against nil placeholders by checking for empty string, because the value would always be non-empty. So this fixes a matchers like this:
These matchers when inside a proxy
handle_response
should not match when the response had a non-empty header value (first one because ofnot
negating empty string, and the regexp requiring at least one character), but instead it did match because the actual string was<nil>
.