From fcde6ff6898ea6c324dd552328dde3d466a8bce1 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Fri, 19 Jan 2024 18:57:19 -0500 Subject: [PATCH] Fix client.rs - properly return Err on invalid header (fix #28) --- src/client.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 8a8a24f..003c66c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -56,7 +56,9 @@ pub async fn canonical_path(path: String) -> Result, String> { // If Reddit responds with a 301, then the path is redirected. 301 => match res.headers().get(header::LOCATION) { Some(val) => { - let original = val.to_str().unwrap(); + let Some(original) = val.to_str().ok() else { + return Err("Unable to decode Location header.".to_string()); + }; // We need to strip the .json suffix from the original path. // In addition, we want to remove share parameters. // Cut it off here instead of letting it propagate all the way