Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running tests with a {{host}} variable missing a protocol panics. #1716

Closed
Jayshua opened this issue Jul 3, 2023 · 1 comment · Fixed by #1728
Closed

Running tests with a {{host}} variable missing a protocol panics. #1716

Jayshua opened this issue Jul 3, 2023 · 1 comment · Fixed by #1728
Labels
bug Something isn't working
Milestone

Comments

@Jayshua
Copy link

Jayshua commented Jul 3, 2023

What is the current bug behavior?

Running tests with a {{host}} variable missing a protocol panics.

Steps to reproduce

# Reproducing requires some type of server running at localhost:4000
echo "GET {{host}}" > test.hurl
hurl --variable host=localhost:4000 test.hurl
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hurl-4.0.0/src/http/request.rs:74:24
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:117:5
   3: hurl::http::request::Request::base_url
   4: hurl::http::client::Client::execute_with_redirect
   5: hurl::runner::entry::run
   6: hurl::runner::hurl_file::run
   7: hurl::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

What is the expected correct behavior?

An error message. Something like "Invalid URL" or "URLs must have a protocol."

Execution context

  • Hurl Version: 4.0.0
  • Operating system and version: Void Linux, Kernel 6.1

Possible fixes

diff --git a/packages/hurl/src/http/request.rs b/packages/hurl/src/http/request.rs
index 7737fe8d..9a77b090 100644
--- a/packages/hurl/src/http/request.rs
+++ b/packages/hurl/src/http/request.rs
@@ -71,7 +71,7 @@ impl Request {
         let base_url = format!(
             "{}://{}{}",
             url.scheme(),
-            url.host().unwrap(),
+            url.host().ok_or_else(|| HttpError::InvalidUrl(self.url.clone()))?,
             if let Some(port) = url.port() {
                 format!(":{port}")
             } else {
@Jayshua Jayshua added the bug Something isn't working label Jul 3, 2023
@jcamiel
Copy link
Collaborator

jcamiel commented Jul 3, 2023

Hi @Jayshua, nice catch!
Thanks for the issue, we'll fix it asap

@jcamiel jcamiel added this to the 4.1.0 milestone Jul 3, 2023
@jcamiel jcamiel linked a pull request Jul 6, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants