-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vars: Make nil values act as empty string instead of "<nil>"
#6174
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is better... thanks. I'm not 100% convinced it will be for everyone, though, as in some cases I could see a nil value wanting to be explicitly printed as nil, as opposed to empty, but, let's see how it goes 👍
I disagree with the assertion that an empty string and nil can be aliased @mholt @francislavoie "" is simple not the same as nil/null. Just like in databases, those are two very different "values" 1/ a definitive, distinct value ("") Simply equaling those two has never ended well, based on my experience - especially in a late stage with existing data, config, etc. Haven't finished research the full impact, but this is one major difference in handling data between a stable 2.7.6 and a crashing 2.8.4. we found so far when trying to understand those 343 changed files with 17,585 additions and 6,030 deletions leading to our repeated unreproducible production crash |
On the root issue
I don't understand why that was a requirement. We have not had this use case, so may be missing something, |
Using a special constant string for nil is not better than using the known zero value of a string. It simply moves the goalpost. If you really need to match for exactly nil, then you can use the
|
The current solution equals/aliases them, when they are not equal. Having 2 separate strings "" and "" would actually still be better
Interesting, that's a new, thanks! |
And using a special string like |
I agree, but I think the context of this issue is that printing a nil value as a string of As Francis mentioned, you can use CEL for proper type-safe comparison. But the built-in matcher configs that only get string inputs have no good way to represent |
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>
.