Skip to content
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

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

francislavoie
Copy link
Member

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 and vars_regexp matchers were turning placeholders that return no value (nil) into literally the string "<nil>" because of the default: case doing fmt.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:

@foo not vars {rp.header.Foo} ""
@bar vars_regexp bar {rp.header.Bar} ^(.+)$

These matchers when inside a proxy handle_response should not match when the response had a non-empty header value (first one because of not negating empty string, and the regexp requiring at least one character), but instead it did match because the actual string was <nil>.

@francislavoie francislavoie added the bug 🐞 Something isn't working label Mar 17, 2024
@francislavoie francislavoie added this to the v2.8.0 milestone Mar 17, 2024
Copy link
Member

@mholt mholt left a 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 👍

@mholt mholt merged commit d132584 into master Mar 21, 2024
25 checks passed
@mholt mholt deleted the vars-match-nil branch March 21, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants