Skip to content

Commit be09414

Browse files
committed
normalize line endings
1 parent 0c071c7 commit be09414

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

coderd/notifications/notifications_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,13 @@ func TestNotificationTemplates_Golden(t *testing.T) {
13351335
}
13361336
}
13371337

1338+
// normalizeLineEndings ensures that all line endings are normalized to \n.
1339+
// Required for Windows compatibility.
1340+
func normalizeLineEndings(content []byte) []byte {
1341+
content = bytes.ReplaceAll(content, []byte("\r\n"), []byte("\n"))
1342+
return bytes.ReplaceAll(content, []byte("\r"), []byte("\n"))
1343+
}
1344+
13381345
func normalizeGoldenEmail(content []byte) []byte {
13391346
const (
13401347
constantDate = "Fri, 11 Oct 2024 09:03:06 +0000"
@@ -1355,6 +1362,7 @@ func normalizeGoldenEmail(content []byte) []byte {
13551362
content = dateRegex.ReplaceAll(content, []byte("Date: "+constantDate))
13561363
content = messageIDRegex.ReplaceAll(content, []byte("Message-Id: "+constantMessageID))
13571364
content = bytes.ReplaceAll(content, boundary, []byte(constantBoundary))
1365+
content = normalizeLineEndings(content)
13581366

13591367
return content
13601368
}
@@ -1363,6 +1371,7 @@ func normalizeGoldenWebhook(content []byte) []byte {
13631371
const constantUUID = "00000000-0000-0000-0000-000000000000"
13641372
uuidRegex := regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`)
13651373
content = uuidRegex.ReplaceAll(content, []byte(constantUUID))
1374+
content = normalizeLineEndings(content)
13661375

13671376
return content
13681377
}

0 commit comments

Comments
 (0)