Fix clippy warnings

This commit is contained in:
Matthew Esposito 2023-12-26 18:27:25 -05:00
parent b0f985c687
commit c5d11f220e
No known key found for this signature in database
5 changed files with 24 additions and 35 deletions

View File

@ -49,14 +49,14 @@ pub async fn canonical_path(path: String) -> Result<Option<String>, String> {
let status = res.status().as_u16(); let status = res.status().as_u16();
match status { match status {
429 => return Err("Too many requests.".to_string()), 429 => Err("Too many requests.".to_string()),
// If Reddit responds with a 2xx, then the path is already canonical. // If Reddit responds with a 2xx, then the path is already canonical.
200..=299 => return Ok(Some(path)), 200..=299 => Ok(Some(path)),
// If Reddit responds with anything other than 3xx (except for the 2xx as // If Reddit responds with anything other than 3xx (except for the 2xx as
// above), return a None. // above), return a None.
300..=399 => return Ok(None), 300..=399 => Ok(None),
_ => Ok( _ => Ok(
res res

View File

@ -21,7 +21,7 @@ pub(crate) static INSTANCE_INFO: Lazy<InstanceInfo> = Lazy::new(InstanceInfo::ne
pub async fn instance_info(req: Request<Body>) -> Result<Response<Body>, String> { pub async fn instance_info(req: Request<Body>) -> Result<Response<Body>, String> {
// This will retrieve the extension given, or create a new string - which will // This will retrieve the extension given, or create a new string - which will
// simply become the last option, an HTML page. // simply become the last option, an HTML page.
let extension = req.param("extension").unwrap_or(String::new()); let extension = req.param("extension").unwrap_or_default();
let response = match extension.as_str() { let response = match extension.as_str() {
"yaml" | "yml" => info_yaml(), "yaml" | "yml" => info_yaml(),
"txt" => info_txt(), "txt" => info_txt(),

View File

@ -325,14 +325,13 @@ async fn main() {
// Instance info page // Instance info page
app.at("/info").get(|r| instance_info::instance_info(r).boxed()); app.at("/info").get(|r| instance_info::instance_info(r).boxed());
app.at("/info.:extension").get(|r| instance_info::instance_info(r).boxed()); app.at("/info.:extension").get(|r| instance_info::instance_info(r).boxed());
// Handle obfuscated share links. // Handle obfuscated share links.
// Note that this still forces the server to follow the share link to get to the post, so maybe this wants to be updated with a warning before it follow it // Note that this still forces the server to follow the share link to get to the post, so maybe this wants to be updated with a warning before it follow it
app.at("/r/:sub/s/:id").get(|req: Request<Body>| { app.at("/r/:sub/s/:id").get(|req: Request<Body>| {
Box::pin(async move { Box::pin(async move {
let sub = req.param("sub").unwrap_or_default(); let sub = req.param("sub").unwrap_or_default();
match req.param("id").as_deref() { match req.param("id").as_deref() {
// Share link // Share link
Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/r/{}/s/{}", sub, id)).await { Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/r/{}/s/{}", sub, id)).await {
Ok(Some(path)) => Ok(redirect(path.split('?').next().unwrap_or_default().to_string())), Ok(Some(path)) => Ok(redirect(path.split('?').next().unwrap_or_default().to_string())),
@ -345,7 +344,7 @@ async fn main() {
} }
}) })
}); });
app.at("/:id").get(|req: Request<Body>| { app.at("/:id").get(|req: Request<Body>| {
Box::pin(async move { Box::pin(async move {
match req.param("id").as_deref() { match req.param("id").as_deref() {

View File

@ -353,14 +353,6 @@ fn determine_compressor(accept_encoding: String) -> Option<CompressionType> {
impl PartialOrd for CompressorCandidate { impl PartialOrd for CompressorCandidate {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
// Guard against NAN, both on our end and on the other.
if self.q.is_nan() || other.q.is_nan() {
return None;
};
// f64 and CompressionType are ordered, except in the case
// where the f64 is NAN (which we checked against), so we
// can safely return a Some here.
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }

View File

@ -604,23 +604,23 @@ impl Preferences {
} }
Self { Self {
available_themes: themes, available_themes: themes,
theme: setting(&req, "theme"), theme: setting(req, "theme"),
front_page: setting(&req, "front_page"), front_page: setting(req, "front_page"),
layout: setting(&req, "layout"), layout: setting(req, "layout"),
wide: setting(&req, "wide"), wide: setting(req, "wide"),
show_nsfw: setting(&req, "show_nsfw"), show_nsfw: setting(req, "show_nsfw"),
blur_nsfw: setting(&req, "blur_nsfw"), blur_nsfw: setting(req, "blur_nsfw"),
use_hls: setting(&req, "use_hls"), use_hls: setting(req, "use_hls"),
hide_hls_notification: setting(&req, "hide_hls_notification"), hide_hls_notification: setting(req, "hide_hls_notification"),
autoplay_videos: setting(&req, "autoplay_videos"), autoplay_videos: setting(req, "autoplay_videos"),
fixed_navbar: setting_or_default(&req, "fixed_navbar", "on".to_string()), fixed_navbar: setting_or_default(req, "fixed_navbar", "on".to_string()),
disable_visit_reddit_confirmation: setting(req, "disable_visit_reddit_confirmation"), disable_visit_reddit_confirmation: setting(req, "disable_visit_reddit_confirmation"),
comment_sort: setting(&req, "comment_sort"), comment_sort: setting(req, "comment_sort"),
post_sort: setting(&req, "post_sort"), post_sort: setting(req, "post_sort"),
subscriptions: setting(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), subscriptions: setting(req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
filters: setting(&req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), filters: setting(req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
hide_awards: setting(&req, "hide_awards"), hide_awards: setting(req, "hide_awards"),
hide_score: setting(&req, "hide_score"), hide_score: setting(req, "hide_score"),
} }
} }
} }
@ -1074,9 +1074,7 @@ mod tests {
#[test] #[test]
fn rewrite_urls_keeps_intentional_backslashes() { fn rewrite_urls_keeps_intentional_backslashes() {
assert_eq!( assert_eq!(
rewrite_urls( rewrite_urls("printf \"\\npolkit.addRule(function(action, subject)"),
"printf \"\\npolkit.addRule(function(action, subject)"
),
"printf \"\\npolkit.addRule(function(action, subject)" "printf \"\\npolkit.addRule(function(action, subject)"
); );
} }