nealrichardson / httptest

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

Mock file names with special characters are not matched correctly #32

Closed natbprice closed 4 years ago

natbprice commented 4 years ago

I am performing a GET request against Azure Table Service REST API. You can see the request format here: https://docs.microsoft.com/en-us/rest/api/storageservices/query-entities#request

I am able to generate mock files, but I think these files are not being found when using use_mock_api(). The error message would be clearer if it stated something to the effect of "Mock file not found", but I just get an error with my request and the name of the mock file which is not very helpful for debugging.

Error: GET https://mystorageaccount.table.core.windows.net/MyTable(PartitionKey='1',RowKey='01daa220815781f3885bead08130bace5635d83387bfcc674d48b7dda77f31ac959601038914ccf25e7549715a2a0482e8aa06e923f858686fa1b0e0f6ed49d1') (mystorageaccount.table.core.windows.net/MyTable(PartitionKey='1',RowKey='01daa220815781f3885bead08130bace5635d83387bfcc674d48b7dda77f31ac959601038914ccf25e7549715a2a0482e8aa06e923f858686fa1b0e0f6ed49d1').json)

I believe I have traced the error to the following line:

https://github.com/nealrichardson/httptest/blob/611fa7a375ec3294b91efac70e963b02df4c1a0c/R/mock-api.R#L167

I think you should treat the mock file name as literal to account for special characters that are not escaped. This seemed to work for me:

mockbasename <- paste0("^\\Q", basename(mp), "\\E.[[:alnum:]]*$")

nealrichardson commented 4 years ago

Thanks. Would you be interested in submitting a PR?

natbprice commented 4 years ago

I submitted it. Thanks for fast response!