You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The form.EncodeToValues interface used in the WithQueryObject function will escape the empty value in the query object into an empty string "", such as the number 0, or a length 0 of array/slice/map etc.
Please provide an option to turn off this feature when create httpexpect.Expect, (the form library can create an Encoder and then call KeepZeros(false) to disable this feature)
The text was updated successfully, but these errors were encountered:
gavv
changed the title
WithQueryObject encode empty values to empty string ''
WithQueryObject encode empty values to empty string
Mar 2, 2025
You can now use WithQueryEncoder() with three encoders available:
// QueryEncoderGoogle encodes query using google/go-querystring package.// Query object should be a struct annotated with `url` tags.// See https://github.com/google/go-querystring.QueryEncoderGoogle// QueryEncoderForm encodes query using ajg/form package.// Query object can be arbitrary type including maps and structs// annotated with `form` tags.// See https://github.com/ajg/form.QueryEncoderForm// QueryEncoderFormKeepZeros is same as QueryEncoderForm, but with KeepZeros// flag enabled. With this flag, encoder keeps zero (default) values in their// literal form when encoding, and returns the former; by default zero values// are not kept, but are rather encoded as the empty string.QueryEncoderFormKeepZeros
Please provide an option to turn off this feature when create httpexpect.Expect
Such options are usually per-request, because otherwise httpexpect.Config would quickly become a mess. But you can easily make it global by using a request builder:
e := httpexpect.Default(t, "http://example.com")
e2 := e.Builder(func (req *httpexpect.Request) {
req.WithQueryEncoder(httpexpect.QueryEncoderFormKeepZeros)
})
// now use e2 everywhere
I'm closing the issue, but feel free to re-open if you have any troubles.
The
form.EncodeToValues
interface used in theWithQueryObject
function will escape theempty value
in thequery object
into an empty string""
, such as the number0
, or a length 0 ofarray/slice/map
etc.Please provide an option to turn off this feature when create
httpexpect.Expect
, (theform
library can create anEncoder
and then callKeepZeros(false)
to disable this feature)The text was updated successfully, but these errors were encountered: