diff --git a/src/error.rs b/src/error.rs index ae01186..81592e2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -31,13 +31,13 @@ pub enum Error { impl IntoResponse for Error { fn into_response(self) -> axum::response::Response { match self { - Self::PhraseInvalid => (StatusCode::BAD_REQUEST, "phrase is not valid"), - Self::BinNotFound => (StatusCode::NOT_FOUND, "bin does not exist"), - Self::DataFileExists => (StatusCode::CONFLICT, "bin already has data"), - Self::ParseTtl => (StatusCode::BAD_REQUEST, "invalid ttl class"), + Self::PhraseInvalid => (StatusCode::BAD_REQUEST, "url is not valid\n"), + Self::BinNotFound => (StatusCode::NOT_FOUND, "bin does not exist\n"), + Self::DataFileExists => (StatusCode::CONFLICT, "bin already contains data\n"), + Self::ParseTtl => (StatusCode::BAD_REQUEST, "invalid ttl class\n"), _ => { error!("{:?}", self); - (StatusCode::INTERNAL_SERVER_ERROR, "internal server error") + (StatusCode::INTERNAL_SERVER_ERROR, "internal server error\n") } } .into_response() diff --git a/src/util.rs b/src/util.rs index 8e382ea..9ba2fd8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -33,10 +33,12 @@ impl FromStr for Phrase { type Err = Error; fn from_str(s: &str) -> Result { - if s.chars().any(|x| !x.is_ascii_alphanumeric()) { + if s.chars().any(|x| !x.is_ascii_alphanumeric() && x != '.') { Err(Error::PhraseInvalid) } else { - Ok(Self(s.to_string())) + Ok(Self( + s.chars().take(s.find('.').unwrap_or(s.len())).collect(), + )) } } }