Skip to content

Commit

Permalink
fix(search): handle queries' urlencoding (#264)
Browse files Browse the repository at this point in the history
* fix(search): handle queries' urlencoding

* fix(search): handle queries' urlencoding
  • Loading branch information
sigaloid authored Sep 25, 2024
1 parent 72f7d9d commit 403513a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hyper::{Body, Request, Response};
use askama::Template;
use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};

// STRUCTS
#[derive(Template)]
Expand Down Expand Up @@ -72,11 +72,15 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
}

let query = match COMMENT_SEARCH_CAPTURE.captures(&url) {
let query_body = match COMMENT_SEARCH_CAPTURE.captures(&url) {
Some(captures) => captures.get(1).unwrap().as_str().replace("%20", " ").replace('+', " "),
None => String::new(),
};

let query_string = format!("q={query_body}&type=comment");
let form = url::form_urlencoded::parse(query_string.as_bytes()).collect::<HashMap<_, _>>();
let query = form.get("q").unwrap().clone().to_string();

let comments = match query.as_str() {
"" => parse_comments(&response[1], &post.permalink, &post.author.name, highlighted_comment, &get_filters(&req), &req),
_ => query_comments(&response[1], &post.permalink, &post.author.name, highlighted_comment, &get_filters(&req), &query, &req),
Expand Down

0 comments on commit 403513a

Please sign in to comment.