Skip to content

Commit

Permalink
SDP-1343 Fix HTML escaping (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
marwen-abid authored Sep 17, 2024
1 parent 3c64059 commit b7c47bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/htmltemplate/htmltemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ExecuteHTMLTemplate(templateName string, data interface{}) (string, error)
}

type EmptyBodyEmailTemplate struct {
Body string
Body template.HTML
}

func ExecuteHTMLTemplateForEmailEmptyBody(data EmptyBodyEmailTemplate) (string, error) {
Expand Down
3 changes: 2 additions & 1 deletion internal/htmltemplate/htmltemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package htmltemplate
import (
"crypto/rand"
"fmt"
"html/template"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -43,7 +44,7 @@ func Test_ExecuteHTMLTemplateForEmailEmptyBody(t *testing.T) {
randomStr := fmt.Sprintf("%x", b)[:10]

// check if the random string is imprinted in the template
inputData := EmptyBodyEmailTemplate{Body: randomStr}
inputData := EmptyBodyEmailTemplate{Body: template.HTML(randomStr)}
templateStr, err := ExecuteHTMLTemplateForEmailEmptyBody(inputData)
require.NoError(t, err)
require.Contains(t, templateStr, randomStr)
Expand Down
3 changes: 2 additions & 1 deletion internal/message/aws_ses_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package message

import (
"fmt"
"html/template"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -51,7 +52,7 @@ func (a *awsSESClient) SendMessage(message Message) error {

// generateAWSEmail generates the email object to send an email through AWS SES.
func generateAWSEmail(message Message, sender string) (*ses.SendEmailInput, error) {
html, err := htmltemplate.ExecuteHTMLTemplateForEmailEmptyBody(htmltemplate.EmptyBodyEmailTemplate{Body: message.Message})
html, err := htmltemplate.ExecuteHTMLTemplateForEmailEmptyBody(htmltemplate.EmptyBodyEmailTemplate{Body: template.HTML(message.Message)})
if err != nil {
return nil, fmt.Errorf("generating html template: %w", err)
}
Expand Down

0 comments on commit b7c47bd

Please sign in to comment.