The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(util): handle missing scheme in url normalization
Steven Enamakel7455aeaf7c19
diff --git a/crates/openhuman-core/src/config/app_env_tests.rs b/crates/openhuman-core/src/config/app_env_tests.rsnew file mode 100644index 0000000000..7cc9f89d61--- /dev/null+++ b/crates/openhuman-core/src/config/app_env_tests.rs@@ -0,0 +1,9 @@+use super::*;++#[test]+fn is_staging_app_env_matches_staging_case_insensitively() {+ assert!(is_staging_app_env(Some("staging")));+ assert!(is_staging_app_env(Some(" STAGING ")));+ assert!(!is_staging_app_env(Some("production")));+ assert!(!is_staging_app_env(None));+}diff --git a/crates/openhuman-core/src/util/url.rs b/crates/openhuman-core/src/util/url.rsindex 5bc84a9587..977c3d2384 100644--- a/crates/openhuman-core/src/util/url.rs+++ b/crates/openhuman-core/src/util/url.rs@@ -37,7 +37,7 @@ pub fn normalize_backend_api_base_url(url: &str) -> String {}let parsed =- url::Url::parse(&normalized).or_else(|_| url::Url::parse(&format!("https://{normalized}")));+ ::url::Url::parse(&normalized).or_else(|_| ::url::Url::parse(&format!("https://{normalized}")));let Ok(mut parsed) = parsed else {// Unparseable even with the scheme prefix — return as-is; the caller@@ -76,7 +76,7 @@ pub fn join_url(base: &str, path: &str) -> String {return normalize_api_base_url(base);}- match url::Url::parse(base) {+ match ::url::Url::parse(base) {Ok(parsed) => match parsed.join(path) {Ok(joined) => joined.to_string().trim_end_matches('/').to_string(),Err(_) => fallback_concat(base, path),@@ -85,7 +85,7 @@ pub fn join_url(base: &str, path: &str) -> String {}}-/// Last-resort URL join used when `url::Url::parse` rejects the base.+/// Last-resort URL join used when `::url::Url::parse` rejects the base.////// Guarantees a slash between `base` and `path` regardless of whether either/// carries one, but does not otherwise validate the resulting string.@@ -107,13 +107,13 @@ fn fallback_concat(base: &str, path: &str) -> String {/// (`::ffff:127.0.0.1`), the bare IPv6 loopback (`::1`), and all three/// IPv4 loopback forms classify correctly.#[inline]-pub fn host_is_local(parsed: &url::Url) -> bool {+pub fn host_is_local(parsed: &::url::Url) -> bool {match parsed.host() {- Some(url::Host::Ipv4(addr)) => {+ Some(::url::Host::Ipv4(addr)) => {addr.is_loopback() || addr.is_unspecified() || addr.is_private()}- Some(url::Host::Ipv6(addr)) => addr.is_loopback() || addr.is_unspecified(),- Some(url::Host::Domain(name)) => {+ Some(::url::Host::Ipv6(addr)) => addr.is_loopback() || addr.is_unspecified(),+ Some(::url::Host::Domain(name)) => {let h = name.to_ascii_lowercase();h == "localhost" || h.ends_with(".localhost")}diff --git a/crates/openhuman-core/src/util/url_tests.rs b/crates/openhuman-core/src/util/url_tests.rsnew file mode 100644index 0000000000..a9ae4ba198--- /dev/null+++ b/crates/openhuman-core/src/util/url_tests.rs@@ -0,0 +1,45 @@+use super::*;++#[test]+fn join_url_replaces_any_base_path_with_the_absolute_route() {+ assert_eq!(join_url("https://h.example", "/auth/me"), "https://h.example/auth/me");+ assert_eq!(+ join_url("https://h.example/openai/v1/chat/completions", "/agent-integrations/x"),+ "https://h.example/agent-integrations/x"+ );+ assert_eq!(join_url(" https://h.example/ ", ""), "https://h.example");+ assert_eq!(join_url("not a url", "/x"), "not a url/x");+ assert_eq!(join_url("not a url/", "x"), "not a url/x");+}++#[test]+fn normalize_backend_api_base_url_keeps_only_the_origin() {+ assert_eq!(+ normalize_backend_api_base_url("https://h.example/openai/v1/chat/completions?x=1#f"),+ "https://h.example"+ );+ assert_eq!(+ normalize_backend_api_base_url("h.example/openai/v1"),+ "https://h.example"+ );+ assert_eq!(normalize_backend_api_base_url(" "), "");+ assert_eq!(normalize_api_base_url(" https://h.example// "), "https://h.example");+}++#[test]+fn host_is_local_classifies_loopback_private_and_localhost() {+ let local = [+ "http://127.0.0.1:1",+ "http://[::1]:1",+ "http://0.0.0.0",+ "http://10.0.0.2",+ "http://localhost",+ "http://app.localhost",+ ];+ for raw in local {+ assert!(host_is_local(&::url::Url::parse(raw).unwrap()), "{raw}");+ }+ for raw in ["https://h.example", "http://8.8.8.8"] {+ assert!(!host_is_local(&::url::Url::parse(raw).unwrap()), "{raw}");+ }+}