hurl icon indicating copy to clipboard operation
hurl copied to clipboard

Binary content no longer showing in terminal.

Open bogdiw opened this issue 1 year ago • 7 comments

Solves #2306

Added an additional check to see if the output is binary. If so, an error message is printed.

bogdiw avatar Jan 13 '24 19:01 bogdiw

Thanks @bogdiw for your PR. First, you can check the Contributing guide to sign your commits and run the integration tests.

Then, the behaviour in Hurl needs to be consistent with curl:

  • the warnings only applies when outputing to a terminal
  • output can still written with --output option ...

I'm going first to implement (#2312) as a prerequisite for your PR.

fabricereix avatar Jan 14 '24 08:01 fabricereix

I've solved the cargo clippy errors, but the /tests_ok/assert_base64.py it's failing. Any advice in handling this? Maybe adding the test to /tests_failed should change it because now we don't print binary on screen anymore.

bogdiw avatar Jan 14 '24 15:01 bogdiw

This test must clearly pass. You can always double check with curl:

$ curl 'http://localhost:8000/assert-base64'
line1
line2
line3 

fabricereix avatar Jan 14 '24 20:01 fabricereix

Ok, thank you. I'll try to fix the code then.

bogdiw avatar Jan 15 '24 02:01 bogdiw

Hi @bogdiw the code doesn't seem OK to me:

let is_binary = response.body.iter().any(|&byte| !(32..=126).contains(&byte));

I don't understand why this condition is linked to the output being binary and doesn't seem correct to me. Could you explain it?

jcamiel avatar Jan 15 '24 09:01 jcamiel

Hi @jcamiel my main idea was to check whether any byte in the response body is outside the ASCII range of printable characters (32 to 126).

bogdiw avatar Jan 15 '24 10:01 bogdiw

I think we can have false positive doing this. We should try to see how curl is doing it. In the proposed PR, I see another problem: we don't want to check every byte for a big file for instance (testing if a 1GB text file is binary would imply testing every bytes).

jcamiel avatar Jan 15 '24 11:01 jcamiel

📆 This PR has been closed because there is no activity (commits/comments) for more than 15 days 😥. Feel free to reopen it with new commits/comments.

hurl-bot avatar Mar 04 '24 03:03 hurl-bot