diff options
author | Jason Song <i@wolfogre.com> | 2023-06-21 17:14:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-21 09:14:34 +0000 |
commit | 59d218987582ae3191a4cb97fbfc4f3aedcff1ad (patch) | |
tree | 6d100fa7ef0926cf7d2434b44d1f2327338daaf3 /modules/templates/util_render_test.go | |
parent | 6a8ebaf22b8e85049ca44158ff7ff7c10c39e0f2 (diff) | |
download | gitea-59d218987582ae3191a4cb97fbfc4f3aedcff1ad.tar.gz gitea-59d218987582ae3191a4cb97fbfc4f3aedcff1ad.zip |
Fix missing commit message body when the message has leading newlines (#25418)
Commit with `echo "\nmessage after a blank line\nsecond line of the
message" | git commit --cleanup=verbatim -F -` and push.
<img width="1139" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/f9a2c28c-e307-4c78-9e31-3d3ace7b9274">
Diffstat (limited to 'modules/templates/util_render_test.go')
-rw-r--r-- | modules/templates/util_render_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/modules/templates/util_render_test.go b/modules/templates/util_render_test.go new file mode 100644 index 0000000000..29d3ed3a56 --- /dev/null +++ b/modules/templates/util_render_test.go @@ -0,0 +1,56 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package templates + +import ( + "context" + "html/template" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRenderCommitBody(t *testing.T) { + type args struct { + ctx context.Context + msg string + urlPrefix string + metas map[string]string + } + tests := []struct { + name string + args args + want template.HTML + }{ + { + name: "multiple lines", + args: args{ + ctx: context.Background(), + msg: "first line\nsecond line", + }, + want: "second line", + }, + { + name: "multiple lines with leading newlines", + args: args{ + ctx: context.Background(), + msg: "\n\n\n\nfirst line\nsecond line", + }, + want: "second line", + }, + { + name: "multiple lines with trailing newlines", + args: args{ + ctx: context.Background(), + msg: "first line\nsecond line\n\n\n", + }, + want: "second line", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, RenderCommitBody(tt.args.ctx, tt.args.msg, tt.args.urlPrefix, tt.args.metas), "RenderCommitBody(%v, %v, %v, %v)", tt.args.ctx, tt.args.msg, tt.args.urlPrefix, tt.args.metas) + }) + } +} |