surf icon indicating copy to clipboard operation
surf copied to clipboard

Crash when malformed uri

Open gmg137 opened this issue 5 years ago • 3 comments

let res = surf::get("abc").recv_string(data).await;

As above, this will cause the program to crash.

gmg137 avatar Jan 02 '20 06:01 gmg137

Hi, thanks for raising! I've been thinking of how to solve this, and what we probably want is to be able to take TryInto<Url> as the type parameter. For that purpose I've filed:

  • https://github.com/servo/rust-url/issues/568
  • https://github.com/servo/rust-url/pull/569

This would require the usage to:

let res = surf::get("abc")?.recv_string(data).await;

Which would provide graceful error handling rather than directly panicking.


However the solution to your exact issue is to use a fullly-formed url. E.g.

let res = surf::get("http://my-domain.com/abc").recv_string(data).await;

yoshuawuyts avatar Jan 10 '20 11:01 yoshuawuyts

Do you still want to take TryInto<Url> as parameters? I think this also applies to other methods. I could help a PR if this is what it prefers to be.

wusyong avatar Mar 17 '20 15:03 wusyong

It looks like TryInto<Url> support is still waiting for a new release of the url crate.

goto-bus-stop avatar Aug 08 '20 07:08 goto-bus-stop