From 7522d419195ae9b852fb50cb5d9bb1295cb81c8f Mon Sep 17 00:00:00 2001 From: Daniel Szabo Date: Sun, 6 Nov 2022 23:47:56 +0200 Subject: [PATCH] Fix #88 Apparently if a multipart field contains multiple dashes, it will be read in multiple chunks and these chunks should be concatenated in order to read the entire field correctly. --- src/endpoints/create.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/endpoints/create.rs b/src/endpoints/create.rs index 591d304..2a88f23 100644 --- a/src/endpoints/create.rs +++ b/src/endpoints/create.rs @@ -118,14 +118,16 @@ pub async fn create( continue; } "content" => { + let mut content = String::from(""); while let Some(chunk) = field.try_next().await? { - new_pasta.content = std::str::from_utf8(&chunk).unwrap().to_string(); + content.push_str(std::str::from_utf8(&chunk).unwrap().to_string().as_str()); new_pasta.pasta_type = if is_valid_url(new_pasta.content.as_str()) { String::from("url") } else { String::from("text") }; } + new_pasta.content = content; continue; } "syntax-highlight" => { @@ -179,7 +181,9 @@ pub async fn create( new_pasta.file = Some(file); new_pasta.pasta_type = String::from("text"); } - _ => {} + field => { + log::error!("Unexpected multipart field: {}", field); + } } }