Skip to content

Commit

Permalink
Merge pull request #177 from inovex/christian
Browse files Browse the repository at this point in the history
fix: allow ugc content in keepDescription transformer
  • Loading branch information
MichaelEischer authored Aug 13, 2024
2 parents 16a5c4d + e90798e commit 24269ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/transformation/keepDescription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions internal/transformation/keepDescription_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -40,9 +41,15 @@ func TestKeepDescription_Transform(t *testing.T) {
},
{
name: "removes html from description",
sourceDescription: "<h1>Headline</h1>",
sourceDescription: "<test>Headline</test><h1>Headline2</h1>",
sinkDescription: "bar",
expectedDescription: "Headline<h1>Headline2</h1>",
},
{
name: "keep html-linebreaks from description",
sourceDescription: "<h1>Headline2</h1><br><br/>ohai\r\n",
sinkDescription: "bar",
expectedDescription: "Headline",
expectedDescription: "<h1>Headline2</h1><br><br/>ohai",
},
{
name: "truncates description after 4000 chars",
Expand Down

0 comments on commit 24269ee

Please sign in to comment.