From 4d167d9abf9aed9f95ec05ae7c4cc0dfcbdd31b9 Mon Sep 17 00:00:00 2001 From: Alexander Huck Date: Fri, 9 Aug 2024 08:56:34 +0200 Subject: [PATCH 1/2] fix: allow ugc content in keepDescription transformer --- internal/transformation/keepDescription.go | 6 +++--- internal/transformation/keepDescription_test.go | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/transformation/keepDescription.go b/internal/transformation/keepDescription.go index e22481b..75b61fc 100644 --- a/internal/transformation/keepDescription.go +++ b/internal/transformation/keepDescription.go @@ -4,8 +4,8 @@ import ( "strings" "github.com/aquilax/truncate" - "github.com/microcosm-cc/bluemonday" "github.com/inovex/CalendarSync/internal/models" + "github.com/microcosm-cc/bluemonday" ) // KeepDescription allows to keep the description of an event. @@ -16,8 +16,8 @@ func (t *KeepDescription) Name() string { } func (t *KeepDescription) Transform(source models.Event, sink models.Event) (models.Event, error) { - // need to remove microsoft html overhead - p := bluemonday.StrictPolicy() + // need to remove microsoft html overhead (the description in outlook contains a lot of '\r\n's) + p := bluemonday.UGCPolicy() description := strings.ReplaceAll(source.Description, "\r\n", "") sanitizedDescription := p.Sanitize(description) sanitizedDescription2 := strings.TrimSpace(sanitizedDescription) diff --git a/internal/transformation/keepDescription_test.go b/internal/transformation/keepDescription_test.go index f35c660..778a3c8 100644 --- a/internal/transformation/keepDescription_test.go +++ b/internal/transformation/keepDescription_test.go @@ -1,10 +1,11 @@ package transformation import ( - "github.com/stretchr/testify/assert" - "github.com/inovex/CalendarSync/internal/models" "strings" "testing" + + "github.com/inovex/CalendarSync/internal/models" + "github.com/stretchr/testify/assert" ) func TestKeepDescription_Transform(t *testing.T) { @@ -40,9 +41,9 @@ func TestKeepDescription_Transform(t *testing.T) { }, { name: "removes html from description", - sourceDescription: "

Headline

", + sourceDescription: "Headline

Headline2

", sinkDescription: "bar", - expectedDescription: "Headline", + expectedDescription: "Headline

Headline2

", }, { name: "truncates description after 4000 chars", From e90798ebf23dad2bfbb8a3265e9bbf530727fb42 Mon Sep 17 00:00:00 2001 From: Alexander Huck Date: Fri, 9 Aug 2024 14:54:29 +0200 Subject: [PATCH 2/2] test: add keep html-linebreaks from description test --- internal/transformation/keepDescription_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/transformation/keepDescription_test.go b/internal/transformation/keepDescription_test.go index 778a3c8..ab15da3 100644 --- a/internal/transformation/keepDescription_test.go +++ b/internal/transformation/keepDescription_test.go @@ -45,6 +45,12 @@ func TestKeepDescription_Transform(t *testing.T) { sinkDescription: "bar", expectedDescription: "Headline

Headline2

", }, + { + name: "keep html-linebreaks from description", + sourceDescription: "

Headline2



ohai\r\n", + sinkDescription: "bar", + expectedDescription: "

Headline2



ohai", + }, { name: "truncates description after 4000 chars", sourceDescription: strings.Repeat("a", 4000),