Put a maximum length on post content

This commit is contained in:
Ben Visness 2021-09-08 22:22:47 -05:00
parent 17bf11b173
commit 0f9a57f62b
1 changed files with 10 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"time"
"git.handmade.network/hmn/hmn/src/db"
"git.handmade.network/hmn/hmn/src/logging"
"git.handmade.network/hmn/hmn/src/models"
"git.handmade.network/hmn/hmn/src/oops"
"git.handmade.network/hmn/hmn/src/parsing"
@ -348,7 +349,16 @@ func DeletePost(
return false
}
const maxPostContentLength = 200000
func CreatePostVersion(ctx context.Context, tx pgx.Tx, postId int, unparsedContent string, ipString string, editReason string, editorId *int) (versionId int) {
if len(unparsedContent) > maxPostContentLength {
logging.ExtractLogger(ctx).Warn().
Str("preview", unparsedContent[:400]).
Msg("Somebody attempted to create an extremely long post. Content was truncated.")
unparsedContent = unparsedContent[:maxPostContentLength-1]
}
parsed := parsing.ParseMarkdown(unparsedContent, parsing.ForumRealMarkdown)
ip := net.ParseIP(ipString)