Skip to content

Commit ba417d3

Browse files
linyihaisyphar
authored andcommitted
Use form_urlencoded::parse to retrive sort by value
1 parent 957874d commit ba417d3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/web/releases.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub(crate) async fn search_handler(
509509
.get("query")
510510
.map(|q| q.to_string())
511511
.unwrap_or_else(|| "".to_string());
512-
let sort_by = params
512+
let mut sort_by = params
513513
.get("sort")
514514
.map(|q| q.to_string())
515515
.unwrap_or_else(|| "relevance".to_string());
@@ -579,6 +579,20 @@ pub(crate) async fn search_handler(
579579
return Err(AxumNope::NoResults);
580580
}
581581

582+
let p = form_urlencoded::parse(query_params.as_bytes());
583+
if let Some(v) = p
584+
.filter_map(|(k, v)| {
585+
if &k == "sort" {
586+
Some(v.to_string())
587+
} else {
588+
None
589+
}
590+
})
591+
.next()
592+
{
593+
sort_by = v;
594+
};
595+
582596
get_search_results(&mut conn, &config, &query_params).await?
583597
} else if !query.is_empty() {
584598
let query_params: String = form_urlencoded::Serializer::new(String::new())
@@ -930,7 +944,7 @@ mod tests {
930944
.any(|el| {
931945
let attributes = el.attributes.borrow();
932946
attributes.get("selected").is_some()
933-
&& attributes.get("value").unwrap().to_string() == "recent-updates"
947+
&& attributes.get("value").unwrap() == "recent-updates"
934948
});
935949
assert!(is_target_option_selected);
936950

0 commit comments

Comments
 (0)