4065: Use url crate port_or_known_default to allow parsing default ports (#4087)
This commit is contained in:
parent
bf702b0d67
commit
2b223d45ea
1 changed files with 30 additions and 1 deletions
|
@ -92,7 +92,7 @@ pub mod url {
|
|||
pub fn port((string,): (String,)) -> Result<Value, Error> {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue