nealrichardson / httptest2

Utilities for testing R 📦s that use httr2
https://enpiar.com/httptest2/
Other
26 stars 4 forks source link

`build_mock_url()` give different paths for the same multipart request #42

Open jmaspons opened 4 months ago

jmaspons commented 4 months ago

I found that the paths on Linux/Mac are different from the Windows one. Only for multipart requests. Could explain the failing test in #40 (but not related to the form_data VS character content), see https://github.com/nealrichardson/httptest2/actions/runs/8881677497/job/24384594955?pr=40 or https://github.com/jmaspons/osmapiR/actions/runs/9210988574/job/25339688825

No idea how to fix it, and difficult to reproduce because it depends on the OS.

nealrichardson commented 3 months ago

This feels familiar and I thought I had dealt with this before. My guess would be that it's a difference of path separators. Probably inserting a gsub("\\", "/", x) in there would standardize. (normalizePath() could do this but it also expands the path, and absolute paths will definitely not match across systems.)

nealrichardson commented 3 months ago

On #40 we saw this happening because of CRLF differences in text files. For multipart forms, if there is a curl::form_file(), we hash the file contents, not the file path, so backslashes shouldn't be relevant.

Reading the source in https://github.com/jmaspons/osmapiR (and in xml2), it wasn't obvious to me where that would be coming from. And even so, it's not obvious what to do about CRLF here, if anything.

jmaspons commented 3 months ago

Seems that you spot the problem and the solutions at https://github.com/jmaspons/osmapiR/pull/28

We can close this issue documenting the trick in the readme or vignette