diff --git a/core/src/fnc/parse.rs b/core/src/fnc/parse.rs index d416c4d2..7d780970 100644 --- a/core/src/fnc/parse.rs +++ b/core/src/fnc/parse.rs @@ -92,7 +92,7 @@ pub mod url { pub fn port((string,): (String,)) -> Result { // Parse the URL match Url::parse(&string) { - Ok(v) => match v.port() { + Ok(v) => match v.port_or_known_default() { Some(v) => Ok(v.into()), None => Ok(Value::None), }, @@ -118,4 +118,33 @@ pub mod url { Err(_) => Ok(Value::None), } } + + #[cfg(test)] + mod tests { + use crate::sql::value::Value; + + #[test] + fn port_default_port_specified() { + let value = super::port(("http://www.google.com:80".to_string(),)).unwrap(); + assert_eq!(value, 80.into()); + } + + #[test] + fn port_nondefault_port_specified() { + let value = super::port(("http://www.google.com:8080".to_string(),)).unwrap(); + assert_eq!(value, 8080.into()); + } + + #[test] + fn port_no_port_specified() { + let value = super::port(("http://www.google.com".to_string(),)).unwrap(); + assert_eq!(value, 80.into()); + } + + #[test] + fn port_no_scheme_no_port_specified() { + let value = super::port(("www.google.com".to_string(),)).unwrap(); + assert_eq!(value, Value::None); + } + } }