From 925b1867de24273dda71a81def69490b220f5218 Mon Sep 17 00:00:00 2001 From: Emma Triphora Date: Tue, 16 Jan 2024 17:02:41 -0500 Subject: [PATCH 1/3] Fix search query parameter validation --- src/models/v2/search.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/v2/search.rs b/src/models/v2/search.rs index 354c0b68..7087b0bd 100644 --- a/src/models/v2/search.rs +++ b/src/models/v2/search.rs @@ -7,6 +7,7 @@ use crate::{routes::v2_reroute, search::ResultSearchProject}; pub struct LegacySearchResults { pub hits: Vec, pub offset: usize, + #[validate(range(max = 100))] pub limit: usize, pub total_hits: usize, } From 0aed688d0b6df52f118a2b605964996f76fe755f Mon Sep 17 00:00:00 2001 From: Emma Triphora Date: Tue, 16 Jan 2024 17:03:45 -0500 Subject: [PATCH 2/3] fix compile --- src/models/v2/search.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/v2/search.rs b/src/models/v2/search.rs index 7087b0bd..4fbfbe08 100644 --- a/src/models/v2/search.rs +++ b/src/models/v2/search.rs @@ -1,9 +1,10 @@ use itertools::Itertools; use serde::{Deserialize, Serialize}; +use validator::Validate; use crate::{routes::v2_reroute, search::ResultSearchProject}; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Validate)] pub struct LegacySearchResults { pub hits: Vec, pub offset: usize, From 3851521446eba4ea16cb8e74b6500c7d9273cf81 Mon Sep 17 00:00:00 2001 From: Emma Triphora Date: Tue, 16 Jan 2024 17:22:29 -0500 Subject: [PATCH 3/3] make it actually work --- src/models/v2/search.rs | 4 +--- src/search/mod.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/models/v2/search.rs b/src/models/v2/search.rs index 4fbfbe08..354c0b68 100644 --- a/src/models/v2/search.rs +++ b/src/models/v2/search.rs @@ -1,14 +1,12 @@ use itertools::Itertools; use serde::{Deserialize, Serialize}; -use validator::Validate; use crate::{routes::v2_reroute, search::ResultSearchProject}; -#[derive(Serialize, Deserialize, Debug, Validate)] +#[derive(Serialize, Deserialize, Debug)] pub struct LegacySearchResults { pub hits: Vec, pub offset: usize, - #[validate(range(max = 100))] pub limit: usize, pub total_hits: usize, } diff --git a/src/search/mod.rs b/src/search/mod.rs index 725958e5..3b6f2c6b 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -191,7 +191,7 @@ pub async fn search_for_project( let offset: usize = info.offset.as_deref().unwrap_or("0").parse()?; let index = info.index.as_deref().unwrap_or("relevance"); - let limit = info.limit.as_deref().unwrap_or("10").parse()?; + let limit = info.limit.as_deref().unwrap_or("10").parse::()?.min(100); let sort = get_sort_index(config, index)?; let meilisearch_index = client.get_index(sort.0).await?;