lipanski / mockito

HTTP mocking for Rust!
MIT License
695 stars 59 forks source link

values with spaces from serde_urlencoded don't match Matcher::UrlEncoded #121

Closed cakekindel closed 4 years ago

cakekindel commented 4 years ago

trivial example to reproduce:

use serde::Serialize;
use serde_urlencoded;
use mockito;

#[derive(Serialize)]
struct Form {
    pub key: String,
}

#[test]
pub fn bug_demo() {
    let _mock = mockito::mock("POST", "/")
        // mockito expects this to be "value%20with%20spaces!"
       .match_body(mockito::Matcher::UrlEncoded("key".into(), "value with spaces!".into()))
       .create();

    reqwest::blocking::Client::new()
        .post(&mockito::server_url())
        // encoded by serde_urlencoded to "value+with+spaces!"
        .form(&Form { key: "value with spaces!".into() })
        .send()
        .unwrap()
        .error_for_status()
        .unwrap(); // <- This panics because mockito responds 501 Not Implemented
}
cakekindel commented 4 years ago

this is on:

cakekindel commented 4 years ago

perhaps a potential solution might be to use a dedicated URL encoding / decoding library (like serde_urlencoded rather than percent-encoding?

lipanski commented 4 years ago

@cakekindel fair point. would you like to open a PR to switch the matcher to using serde_urlencoded? otherwise I'll have a look when I get some time.

cakekindel commented 4 years ago

id love to! ill set aside some time soonish to do so.

lipanski commented 4 years ago

@cakekindel great, thank you!