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

Make Exists Mode for QueryParameters support empty parameters #2568

Open
ppv-milestone opened this issue Aug 12, 2024 Discussed in #2553 · 3 comments
Open

Make Exists Mode for QueryParameters support empty parameters #2568

ppv-milestone opened this issue Aug 12, 2024 Discussed in #2553 · 3 comments
Milestone

Comments

@ppv-milestone
Copy link

Discussed in #2553

Originally posted by ppv-milestone July 17, 2024
We need to match queries to an interface that accepts a request like this:
http://path/component?hello
But according to documentation the "Exists" Mode in QueryParameters will only match against non-empty parameters and our tests show that Prefix, Exact and Contains seem to be following the same (providing "" as a value to match for causes the service to fail).
Also tried with regular expressions in Path, but those does not seem to match on parameters.
Anyone has a workaround for this? Or maybe supporting empty parameters for Exists could be supported in next version?
Thanks a lot in advance!
Br,
Peter

@MihaZupan
Copy link
Member

FWIW the query parameters here is matching what we do for headers:

HeaderMatchMode.Exists => !valueIsEmpty,
HeaderMatchMode.NotExists => valueIsEmpty,
HeaderMatchMode.ExactHeader => !valueIsEmpty && TryMatchExactOrPrefix(matcher, requestHeaderValues),
HeaderMatchMode.HeaderPrefix => !valueIsEmpty && TryMatchExactOrPrefix(matcher, requestHeaderValues),
HeaderMatchMode.Contains => !valueIsEmpty && TryMatchContainsOrNotContains(matcher, requestHeaderValues),
HeaderMatchMode.NotContains => valueIsEmpty || TryMatchContainsOrNotContains(matcher, requestHeaderValues),

QueryParameterMatchMode.Exists => !valueIsEmpty,
QueryParameterMatchMode.Exact => !valueIsEmpty && TryMatch(matcher, requestQueryParameterValues),
QueryParameterMatchMode.Prefix => !valueIsEmpty && TryMatch(matcher, requestQueryParameterValues),
QueryParameterMatchMode.Contains => !valueIsEmpty && TryMatch(matcher, requestQueryParameterValues),
QueryParameterMatchMode.NotContains => valueIsEmpty || TryMatch(matcher, requestQueryParameterValues),

and the behavior was intentional for headers at least.
I'd find it surprising if the two were inconsistent.

@ppv-milestone
Copy link
Author

FWIW the query parameters here is matching what we do for headers:

HeaderMatchMode.Exists => !valueIsEmpty,
HeaderMatchMode.NotExists => valueIsEmpty,
HeaderMatchMode.ExactHeader => !valueIsEmpty && TryMatchExactOrPrefix(matcher, requestHeaderValues),
HeaderMatchMode.HeaderPrefix => !valueIsEmpty && TryMatchExactOrPrefix(matcher, requestHeaderValues),
HeaderMatchMode.Contains => !valueIsEmpty && TryMatchContainsOrNotContains(matcher, requestHeaderValues),
HeaderMatchMode.NotContains => valueIsEmpty || TryMatchContainsOrNotContains(matcher, requestHeaderValues),

QueryParameterMatchMode.Exists => !valueIsEmpty,
QueryParameterMatchMode.Exact => !valueIsEmpty && TryMatch(matcher, requestQueryParameterValues),
QueryParameterMatchMode.Prefix => !valueIsEmpty && TryMatch(matcher, requestQueryParameterValues),
QueryParameterMatchMode.Contains => !valueIsEmpty && TryMatch(matcher, requestQueryParameterValues),
QueryParameterMatchMode.NotContains => valueIsEmpty || TryMatch(matcher, requestQueryParameterValues),

and the behavior was intentional for headers at least. I'd find it surprising if the two were inconsistent.

Why do you assume the behavior was intentional for headers and not just the easiest approach? To me it sounds a bit counter-intuitive that Exists goes on whether it has a value instead of whether it actually is present or not - both for headers and query parameters.

@Tratcher
Copy link
Member

It was intentional for headers. Empty headers have no semantic meaning and may be dropped by intermediaries.

The query situation is a bit different. We assume key-value pairs (?key1=a&key2=b), but having a single key without an equals sign is still meaningful (?key1&key2). AspNetCore isn't great at representing this case, it doesn't distinguish between key1= and key1.

@MihaZupan MihaZupan added this to the Backlog milestone Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants