From d62a3ab86b31b912ac5f55dcf51127dd17fff3d9 Mon Sep 17 00:00:00 2001
From: spikecodes <19519553+spikecodes@users.noreply.github.com>
Date: Sat, 30 Jan 2021 17:50:26 -0800
Subject: [PATCH] Refactor redirect path setting
---
src/subreddit.rs | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/subreddit.rs b/src/subreddit.rs
index 11b3f0e..dac7f2c 100644
--- a/src/subreddit.rs
+++ b/src/subreddit.rs
@@ -100,18 +100,16 @@ pub async fn subscriptions(req: HttpRequest) -> HttpResponse {
// Redirect back to subreddit
// check for redirect parameter if unsubscribing from outside sidebar
let redirect_path = param(&req.uri().to_string(), "redirect");
- let path;
-
- if redirect_path.len() > 1 && redirect_path.chars().nth(0).unwrap() == '/' {
- path = redirect_path;
+ let path = if !redirect_path.is_empty() && redirect_path.starts_with('/') {
+ redirect_path
} else {
- path = format!("/r/{}", sub);
- }
+ format!("/r/{}", sub)
+ };
res
.content_type("text/html")
- .set_header("Location", path.to_string())
- .body(format!("Redirecting to {0}...", path.to_string()))
+ .set_header("Location", path.to_owned())
+ .body(format!("Redirecting to {0}...", path))
}
pub async fn wiki(req: HttpRequest) -> HttpResponse {