vapor/vapor

Vapor URLQueryContainer no longer supports valueless query parameters

daveanderson opened this issue · 4 comments

Describe the bug

Vapor version 4.74.2 and earlier supported the ability to use valueless query parameters as flags.
e.g. For the query parameters

?specialFlag&otherValue=1234

Vapor 4.74.2 supported the ability to check if the specialFlag query parameter was present using the code

let hasSpecialFlag = request.query[Bool.self, at: "specialFlag"] ?? false

where, for the above query parameter string

request.query[Bool.self, at: "specialFlag"]

returns an optional boolean that is true.

Vapor versions after 4.74.2 instead return nil for the same query string. There does not appear to be any other affordance for checking the presence of specialFlag apart from parsing the raw query string.
This regression prevents valueless query parameters from being used.

To Reproduce

Send an appropriate PUT/POST request to a Vapor service where one of the query parameters has no value (and no = sign)

e.g.

?specialFlag&otherValue=1234

And attempt to check for the presence of the specialFlag parameter using

request.query[Bool.self, at: "specialFlag"]

Expected behavior

With Vapor 4.74.2 and earlier

request.query[Bool.self, at: "specialFlag"]

would return an optional true value.

Vapor versions after 4.74.2 return nil and there does not appear to be any other affordance for checking the presence of specialFlag apart from parsing the raw query string.

Environment

  • Vapor Framework version: Any version after 4.74.2
  • Vapor Toolbox version: N/A
  • OS version: macOS Ventura 13.6.3

Are you sure this changed in 4.74.2? That release is from almost a year ago, and this was its only content: f39218e

My project had not been updated for over a year and was running (correctly) with 4.74.2. When I updated the version of Vapor to the latest I found the regression. I then tried a several minor versions newer than 4.74.2 and only found the restored functionality when I moved back to 4.74.2.

So I think the regression is in this set of changes (I didn't figure out which commit). 4.74.2...4.75.0

@daveanderson Found the problem - #3151 fixes it and will be released as soon as it's been reviewed. Thanks for reporting the issue! ❤️

Thank you for the quick fix and added test!