Skip to content

Commit 338e396

Browse files
committed
Fix regression.
1 parent 84d9098 commit 338e396

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/cmd/serve.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async fn handle_request(
8585
return Ok(not_found());
8686
}
8787

88-
let trimmed_path = &path_str[base_path.len()..];
88+
let trimmed_path = &path_str[base_path.len() - 1..];
8989

9090
let original_root = root.clone();
9191
let mut path = RelativePathBuf::new();
@@ -284,7 +284,11 @@ fn construct_url(base_url: &str, no_port_append: bool, interface_port: u16) -> S
284284
format!("{}{}:{}{}", protocol, domain, interface_port, path)
285285
};
286286

287-
full_address
287+
if full_address.ends_with('/') {
288+
full_address
289+
} else {
290+
format!("{}/", full_address)
291+
}
288292
}
289293

290294
#[allow(clippy::too_many_arguments)]
@@ -857,25 +861,25 @@ mod tests {
857861
#[test]
858862
fn test_construct_url_http_protocol() {
859863
let result = construct_url("http://example.com", false, 8080);
860-
assert_eq!(result, "http://example.com:8080");
864+
assert_eq!(result, "http://example.com:8080/");
861865
}
862866

863867
#[test]
864868
fn test_construct_url_https_protocol() {
865869
let result = construct_url("https://example.com", false, 8080);
866-
assert_eq!(result, "https://example.com:8080");
870+
assert_eq!(result, "https://example.com:8080/");
867871
}
868872

869873
#[test]
870874
fn test_construct_url_no_protocol() {
871875
let result = construct_url("example.com", false, 8080);
872-
assert_eq!(result, "http://example.com:8080");
876+
assert_eq!(result, "http://example.com:8080/");
873877
}
874878

875879
#[test]
876880
fn test_construct_url_no_port_append() {
877881
let result = construct_url("https://example.com", true, 8080);
878-
assert_eq!(result, "https://example.com");
882+
assert_eq!(result, "https://example.com/");
879883
}
880884

881885
#[test]

0 commit comments

Comments
 (0)