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

Handle url encoding in query param match #56

Closed
StarpTech opened this issue Dec 16, 2021 · 3 comments · Fixed by #59
Closed

Handle url encoding in query param match #56

StarpTech opened this issue Dec 16, 2021 · 3 comments · Fixed by #59
Labels
bug Something isn't working

Comments

@StarpTech
Copy link

Hi, first of all, thanks for the great library. We found an issue with query_param. According to the documentation, it's not necessary to encode the query value.

Sets a query parameter that needs to be provided.
Attention!: The request query keys and values are implicitly allowed, but is not required to be urlencoded! The value you pass here, however, must be in plain text (i.e. not encoded)!

In order to match, we need to replace spaces with +. I'd expect that this library can handle it for me so I don't need to care about encoding internals.

Reference: https://url.spec.whatwg.org/#url-parsing (spaceAsPlus)

let m = server.mock(|when, then|{
    when.query_param("query", "Metallica is cool".replace(" ", "+"));
    then.status(200);
});

let req = hyper::Request::builder()
    .method(Method::GET)
    .uri(
        Url::parse_with_params(
            "http://example.com/",
            &[
                ("query", "Metallica is cool")
            ],
        )
        .unwrap()
        .to_string(),
    )
    .header("content-type", "application/json")
    .body(Body::empty())
    .unwrap();
@alexliesenfeld
Copy link
Owner

alexliesenfeld commented Dec 18, 2021

Hi @StarpTech, thanks fur submitting this issue.httpmock uses qstring to convert query strings into key/value pairs (see here). It seems that it doesn't handle that situation correctly as it only treats %20 as a space but not +.

The reason seems to be the usage of percent_decode, which in turn only handles "percent" values as per https://url.spec.whatwg.org/#percent-decode.

It seems to be a known open issue in qstring though: algesten/qstring#3. The library seems unmaintained, so it might be a candidate for a replacement in future.

@StarpTech
Copy link
Author

Hi @alexliesenfeld thanks for the detailed response. We could switch to https://github.com/servo/rust-url.

@alexliesenfeld alexliesenfeld added the bug Something isn't working label Dec 22, 2021
@95th 95th mentioned this issue Jan 3, 2022
@alexliesenfeld
Copy link
Owner

Should be fixed in release v0.6.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants