From a09ddbbaf4dbda24aaa7da45d7de7785c1f6cb3e Mon Sep 17 00:00:00 2001 From: Krish Mamtora Date: Wed, 3 Jul 2024 09:04:54 -0400 Subject: [PATCH] Remove carriage returns to sanitizer strings from windows --- internal/api/user.go | 5 +++++ internal/ui/settings_update.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/internal/api/user.go b/internal/api/user.go index d507d550..71d70e9c 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -8,6 +8,7 @@ import ( "errors" "net/http" "regexp" + "strings" "miniflux.app/v2/internal/http/request" "miniflux.app/v2/internal/http/response/json" @@ -86,9 +87,13 @@ func (h *handler) updateUser(w http.ResponseWriter, r *http.Request) { cleanEnd := regexp.MustCompile(`(?m)\r\n\s*$`) if userModificationRequest.BlockFilterEntryRules != nil { *userModificationRequest.BlockFilterEntryRules = cleanEnd.ReplaceAllLiteralString(*userModificationRequest.BlockFilterEntryRules, "") + // Clean carriage returns for Windows environments + *userModificationRequest.BlockFilterEntryRules = strings.ReplaceAll(*userModificationRequest.BlockFilterEntryRules, "\r\n", "\n") } if userModificationRequest.KeepFilterEntryRules != nil { *userModificationRequest.KeepFilterEntryRules = cleanEnd.ReplaceAllLiteralString(*userModificationRequest.KeepFilterEntryRules, "") + // Clean carriage returns for Windows environments + *userModificationRequest.KeepFilterEntryRules = strings.ReplaceAll(*userModificationRequest.KeepFilterEntryRules, "\r\n", "\n") } if validationErr := validator.ValidateUserModification(h.store, originalUser.ID, &userModificationRequest); validationErr != nil { diff --git a/internal/ui/settings_update.go b/internal/ui/settings_update.go index e0059d4d..0e03752d 100644 --- a/internal/ui/settings_update.go +++ b/internal/ui/settings_update.go @@ -6,6 +6,7 @@ package ui // import "miniflux.app/v2/internal/ui" import ( "net/http" "regexp" + "strings" "miniflux.app/v2/internal/http/request" "miniflux.app/v2/internal/http/response/html" @@ -58,6 +59,9 @@ func (h *handler) updateSettings(w http.ResponseWriter, r *http.Request) { cleanEnd := regexp.MustCompile(`(?m)\r\n\s*$`) settingsForm.BlockFilterEntryRules = cleanEnd.ReplaceAllLiteralString(settingsForm.BlockFilterEntryRules, "") settingsForm.KeepFilterEntryRules = cleanEnd.ReplaceAllLiteralString(settingsForm.KeepFilterEntryRules, "") + // Clean carriage returns for Windows environments + settingsForm.BlockFilterEntryRules = strings.ReplaceAll(settingsForm.BlockFilterEntryRules, "\r\n", "\n") + settingsForm.KeepFilterEntryRules = strings.ReplaceAll(settingsForm.KeepFilterEntryRules, "\r\n", "\n") if validationErr := settingsForm.Validate(); validationErr != nil { view.Set("errorMessage", validationErr.Translate(loggedUser.Language))