Merge pull request #938 from Silvertree2010/fix/h911-same-server-ignores-the-scheme-s

Strip default port in same_server when the address has a path
This commit is contained in:
BFlat
2026-10-21 15:34:08 +07:00
committed by GitHub
2 changed files with 14 additions and 1 deletions
+6 -1
View File
@@ -120,7 +120,12 @@ pub fn same_server(a: &str, b: &str) -> bool {
let s = plain_server(s).to_ascii_lowercase();
let s = s.trim_end_matches('/');
let port = if s.starts_with("wss://") { ":443" } else { ":80" };
s.strip_suffix(port).unwrap_or(s).to_string()
let start = s.find("://").map_or(0, |i| i + 3);
let end = s[start..].find('/').map_or(s.len(), |i| start + i);
match s[start..end].strip_suffix(port) {
Some(host) => format!("{}{}{}", &s[..start], host, &s[end..]),
None => s.to_string(),
}
};
norm(a) == norm(b)
}
+8
View File
@@ -583,3 +583,11 @@ fn debug_output_of_a_record_leaves_the_secrets_out() {
no_secrets("debug", &text);
assert!(text.contains("share.example") && text.contains(".."), "{text}");
}
#[test]
fn same_server_ignores_the_default_port_before_a_path() {
use crate::online::same_server;
assert!(same_server("wss://share.example:443/figcraft/", "wss://share.example/figcraft/"));
assert!(same_server("ws://host:80/x", "ws://host/x"));
assert!(!same_server("wss://share.example:8443/figcraft/", "wss://share.example/figcraft/"));
}