-
Notifications
You must be signed in to change notification settings - Fork 390
cookie.get() return value incorrect when called with nonexistent cookie #3634
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
Comments
That's probably because The same would happen with a non-existent header:
|
This test, where a temporary header is used, passes:
I disagree with @dridi when it comes to closing this issue. The documentation clearly states that the return value is an empty string, and comparing the return value with the empty string seems a natural thing to do (even though it is more natural to me to store it in a header first, since you will need it soon after if it is there). We might just keep the code but fix the documentation somehow, but this is unclear to me. The problem here is possibly present at other places in the code where "the empty string" is mentioned. |
This, too, passes, and it is very close to your test case, exploiting the fact that NULL, and not the empty string, is returned:
Would it be acceptable to change the docs to state that the NULL string is returned, and then include examples for testing if the cookie is there, both directly (like here) or via a temporary header (in my previous post)? I am just throwing ideas around, of course. |
I think it's conceptually fine to fix vmod_cookie to match what the manual says, because The downside is that we risk breaking existing VCL code in subtle ways, so I'd probably prefer a docfix. |
the establish culture is to return |
Yeah, clarifying the behavior in the docs sounds fine to me. |
Just to clarify: #3647 is a PR which doc fixes this. Anyone are welcome to comment, of course. After summer, when all the Varnish Cache contributors are back, is probably the time this ticket will be closed. edit: typo/grammar fix |
Awesome, thanks a lot for jumping in on this! |
Expected Behavior
cookie.get() should return an empty string if no such cookie was present in the request header, as documented
Current Behavior
On Varnish 6.6.0, cookie.get() returns something other than an empty string/empty value.
Steps to Reproduce (for bugs)
Simple varnishtest reproducer:
The above test also fails if the condition is changed to
if (!cookie.get("no_such_cookie"))
.cookie.isset()
however works as expected.Context
I wanted to use
cookie.get("no_such_cookie") != ""
to handle both the case where the cookie is not set, or where it's set but the value is empty.Your Environment
The text was updated successfully, but these errors were encountered: