Support website publishing #7

Merged
lx merged 61 commits from feature/website into master 2021-01-15 16:49:51 +00:00
Showing only changes of commit 851893a3f2 - Show all commits

View file

@ -124,7 +124,12 @@ fn authority_to_host(authority: &str) -> Result<&str, Error> {
let mut iter = iter.skip_while(|(_, c)| c != &']'); let mut iter = iter.skip_while(|(_, c)| c != &']');
match iter.next() { match iter.next() {
Some((_, ']')) => iter.next(), Some((_, ']')) => iter.next(),
quentin marked this conversation as resolved Outdated
Outdated
Review

NO!! expect makes us crash (panic) if the condition is not verified, this is not acceptable (we don't want to assume that authority is well formed, maybe hyper checks it for us but maybe not and we don't want to take risks)

NO!! `expect` makes us crash (panic) if the condition is not verified, this is not acceptable (we don't want to assume that authority is well formed, maybe hyper checks it for us but maybe not and we don't want to take risks)
_ => None, _ => {
return Err(Error::BadRequest(format!(
"Authority {} has an illegal format",
authority
)))
}
} }
} }
_ => iter.skip_while(|(_, c)| c != &':').next(), _ => iter.skip_while(|(_, c)| c != &':').next(),
@ -213,10 +218,8 @@ mod tests {
assert_eq!(domain2, "garage.tld"); assert_eq!(domain2, "garage.tld");
let domain3 = authority_to_host("127.0.0.1")?; let domain3 = authority_to_host("127.0.0.1")?;
assert_eq!(domain3, "127.0.0.1"); assert_eq!(domain3, "127.0.0.1");
let domain4 = authority_to_host("[")?; assert!(authority_to_host("[").is_err());
assert_eq!(domain4, "["); assert!(authority_to_host("[hello").is_err());
let domain5 = authority_to_host("[hello")?;
assert_eq!(domain5, "[hello");
Ok(()) Ok(())
} }