Craft Anything: understand how any software works, and craft your own.
Rust
URL sanitization only strips @ userinfo inside the authority (#389)
phatloi0010735a96db2f82
diff --git a/crates/engine/src/tools/web_common.rs b/crates/engine/src/tools/web_common.rsindex 2fb2d993..c28ce2ba 100644--- a/crates/engine/src/tools/web_common.rs+++ b/crates/engine/src/tools/web_common.rs@@ -376,7 +376,8 @@ pub fn sanitize_url(url: &str) -> String {// Strip scheme://userinfo@ → scheme://host…if let Some(scheme_end) = url.find("://") {let (scheme, rest) = url.split_at(scheme_end + 3);- if let Some(at) = rest.find('@') {+ let auth_end = rest.find(['/', '?', '#']).unwrap_or(rest.len());+ if let Some(at) = rest.get(..auth_end).and_then(|a| a.rfind('@')) {let after = rest.get(at + 1..).unwrap_or("");return format!("{scheme}{after}");}@@ -1060,7 +1061,11 @@ mod tests {#[test]fn sanitize_url_strips_userinfo() {assert_eq!(sanitize_url("https://user:pw@host/path?q=1"), "https://host/path?q=1");+ assert_eq!(sanitize_url("https://user:pw@host/@profile"), "https://host/@profile");assert_eq!(sanitize_url("https://host/x"), "https://host/x");+ assert_eq!(sanitize_url("https://example.test/@profile"), "https://example.test/@profile");+ assert_eq!(sanitize_url("https://cdn.example.test/[email protected]"), "https://cdn.example.test/[email protected]");+ assert_eq!(sanitize_url("https://example.test/[email protected]"), "https://example.test/[email protected]");}#[test]