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.
This commit is contained in:
Daniel Szabo 2022-11-06 23:47:56 +02:00
parent c6e5c6f018
commit 7522d41919

View file

@ -118,14 +118,16 @@ pub async fn create(
continue; continue;
} }
"content" => { "content" => {
let mut content = String::from("");
while let Some(chunk) = field.try_next().await? { 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()) { new_pasta.pasta_type = if is_valid_url(new_pasta.content.as_str()) {
String::from("url") String::from("url")
} else { } else {
String::from("text") String::from("text")
}; };
} }
new_pasta.content = content;
continue; continue;
} }
"syntax-highlight" => { "syntax-highlight" => {
@ -179,7 +181,9 @@ pub async fn create(
new_pasta.file = Some(file); new_pasta.file = Some(file);
new_pasta.pasta_type = String::from("text"); new_pasta.pasta_type = String::from("text");
} }
_ => {} field => {
log::error!("Unexpected multipart field: {}", field);
}
} }
} }