Skip to content

Commit

Permalink
made sure that controll and whitespace characters are ignored in the …
Browse files Browse the repository at this point in the history
…group of location-`id`-apis
  • Loading branch information
CommanderStorm committed Apr 28, 2024
1 parent 9586bcb commit b8e7ac4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion server/main-api/src/calendar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pub async fn calendar_handler(
web::Query(args): web::Query<QueryArguments>,
data: web::Data<crate::AppData>,
) -> HttpResponse {
let id = params.into_inner();
let id = params
.into_inner()
.replace(|c: char| c.is_whitespace() || c.is_control(), "");
let location = match get_location(&data.db, &id).await {
Err(e) => {
error!("could not refetch due to {e:?}");
Expand Down
7 changes: 4 additions & 3 deletions server/main-api/src/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ pub async fn get_handler(
web::Query(args): web::Query<utils::LangQueryArgs>,
data: web::Data<crate::AppData>,
) -> HttpResponse {
let Some((probable_id, redirect_url)) =
get_alias_and_redirect(&data.db, &params.into_inner()).await
else {
let id = params
.into_inner()
.replace(|c: char| c.is_whitespace() || c.is_control(), "");
let Some((probable_id, redirect_url)) = get_alias_and_redirect(&data.db, &id).await else {
return HttpResponse::NotFound().body("Not found");
};
let result = if args.should_use_english() {
Expand Down
11 changes: 6 additions & 5 deletions server/main-api/src/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ pub async fn maps_handler(
data: web::Data<crate::AppData>,
) -> HttpResponse {
let start_time = Instant::now();
let id = params.into_inner();
let id = params
.into_inner()
.replace(|c: char| c.is_whitespace() || c.is_control(), "");
let data = match get_localised_data(&data.db, &id, args.should_use_english()).await {
Ok(data) => data,
Err(e) => {
Expand All @@ -130,11 +132,10 @@ pub async fn maps_handler(
let img = construct_image_from_data(data)
.await
.unwrap_or_else(load_default_image);
let res = HttpResponse::Ok().content_type("image/png").body(img);

debug!(
"Preview Generation for {id} took {:?}",
start_time.elapsed()
"Preview Generation for {id} took {elapsed:?}",
elapsed = start_time.elapsed()
);
res
HttpResponse::Ok().content_type("image/png").body(img)
}

0 comments on commit b8e7ac4

Please sign in to comment.