Open iwinux opened 5 months ago
Thanks for this issue.
Yes, URIs are limited to containing characters as per rfc3986, section 2.3, hence the entire URI, including the query, is represented as a string. Is UTF-8 not enough to represent the characters you want to verify or what is your scenario?
As per living standard though, in fact binary content should be possible to represent in the query. So I'd say exposing it in its binary representation in HttpMockRequest
could be an option for such cases.
Non UTF-8 query params are rarely used in modern RESTful APIs. However, the BitTorrent Protocol Specification requires info_hash
to be:
The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file. This value will almost certainly have to be escaped.
So far this is the only situation where I ever want to access the query param in binary representation :(
It seems impossible to assert binary query params encoded by
url::form_urlencoded::byte_serialize
withwhen.query_param("key", "value")
, becauseUrl::parse
(introduced in https://github.com/alexliesenfeld/httpmock/pull/59) converts all query param values intoString
, while all non-utf8 characters are replaced byU+FFFD REPLACEMENT CHARACTER
(see https://github.com/servo/rust-url/issues/219 for details).A possible workaround might be exposing the raw request URL from
HttpMockRequest
, which can be checked by other methods without decoding the query params (e.g.: regexp matching).