From d7d385c0513a5d2329475db77ba454c3516eddb3 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 25 Jan 2024 16:42:43 +0100 Subject: [PATCH] ensure trailing newline --- src/backend/api/article.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/api/article.rs b/src/backend/api/article.rs index a336d28..bf0199b 100644 --- a/src/backend/api/article.rs +++ b/src/backend/api/article.rs @@ -64,7 +64,7 @@ pub(in crate::backend::api) async fn create_article( pub(in crate::backend::api) async fn edit_article( Extension(user): Extension, data: Data, - Form(edit_form): Form, + Form(mut edit_form): Form, ) -> MyResult>> { // resolve conflict if any if let Some(resolve_conflict_id) = edit_form.resolve_conflict_id { @@ -77,6 +77,10 @@ pub(in crate::backend::api) async fn edit_article( if edit_form.summary.is_empty() { return Err(anyhow!("No summary given").into()); } + // ensure trailing newline for clean diffs + if !edit_form.new_text.ends_with('\n') { + edit_form.new_text.push('\n'); + } if edit_form.previous_version_id == original_article.latest_version { // No intermediate changes, simply submit new version