nealrichardson / httptest

A Test Environment for HTTP Requests in R
https://enpiar.com/r/httptest/
Other
79 stars 10 forks source link

Bad redacting when URL parameters are URL themselves #22

Closed ramiromagno closed 5 years ago

ramiromagno commented 5 years ago

Example:

The URL:

https://www.ebi.ac.uk/gwas/rest/api/studies/search/findByEfoUri?uri=http://www.ebi.ac.uk/efo/EFO_0004761&page=0&size=20

Gets written as:

<pkg_path>/tests/testthat/www.ebi.ac.uk/efo/EFO_0004761&page=0&size=20.json

If I use instead:

https://www.ebi.ac.uk/gwas/rest/api/studies/search/findByEfoUri?uri=http:%2f%2fwww.ebi.ac.uk%2fefo%2fEFO_0004761

Then I get the expected mock file:

<pkg_path>/tests/testthat/www.ebi.ac.uk/gwas/rest/api/studies/search/findByEfoUri-5bb3d9.json
nealrichardson commented 5 years ago

Hard for me to say with certainty what's going on without seeing the code you ran to generate this, but it is expected behavior that all occurrences of the regular expression pattern are replaced, not just the first one--that's what gsub() does. And gsub_request/response() do not currently un-escape URL-encoded strings (though one might want it to), so it's not surprising that if / is encoded to %2F that the regular expression won't match it.

ramiromagno commented 5 years ago

OK, thank you!