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

binary query param converted to lossy string #107

Open
iwinux opened this issue Jun 2, 2024 · 2 comments
Open

binary query param converted to lossy string #107

iwinux opened this issue Jun 2, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@iwinux
Copy link

iwinux commented Jun 2, 2024

It seems impossible to assert binary query params encoded by url::form_urlencoded::byte_serialize with when.query_param("key", "value"), because Url::parse (introduced in #59) converts all query param values into String, while all non-utf8 characters are replaced by U+FFFD REPLACEMENT CHARACTER (see servo/rust-url#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).

@alexliesenfeld
Copy link
Owner

alexliesenfeld commented Jun 2, 2024

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.

@alexliesenfeld alexliesenfeld added the enhancement New feature or request label Jun 2, 2024
@iwinux
Copy link
Author

iwinux commented Jun 2, 2024

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 :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants