Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions cft/format/crlf_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package format_test

import (
"testing"

"github.com/aws-cloudformation/rain/cft/format"
"github.com/aws-cloudformation/rain/cft/parse"
)

func TestCRLFComments(t *testing.T) {
// Issue #479: Windows CRLF line endings cause extra blank lines between comments
// Build input with CRLF line endings
input := "AWSTemplateFormatVersion: 2010-09-09\r\n" +
"\r\n" +
"# Comment line 1\r\n" +
"# Comment line 2\r\n" +
"# Comment line 3\r\n" +
"\r\n" +
"Description: Hello World\r\n"

// Same input with LF line endings for comparison
inputLF := "AWSTemplateFormatVersion: 2010-09-09\n" +
"\n" +
"# Comment line 1\n" +
"# Comment line 2\n" +
"# Comment line 3\n" +
"\n" +
"Description: Hello World\n"

tmplCRLF, err := parse.String(input)
if err != nil {
t.Fatalf("Failed to parse CRLF input: %v", err)
}

tmplLF, err := parse.String(inputLF)
if err != nil {
t.Fatalf("Failed to parse LF input: %v", err)
}

outputCRLF := format.String(tmplCRLF, format.Options{})
outputLF := format.String(tmplLF, format.Options{})

t.Logf("CRLF output:\n---\n%s\n---", outputCRLF)
t.Logf("LF output:\n---\n%s\n---", outputLF)

if outputCRLF != outputLF {
t.Errorf("CRLF and LF outputs differ.\nCRLF output:\n%s\nLF output:\n%s", outputCRLF, outputLF)
}
}
1 change: 1 addition & 0 deletions cft/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func Map(input map[string]interface{}) (*cft.Template, error) {

// String returns a cft.Template parsed from a string
func String(input string) (*cft.Template, error) {
input = strings.ReplaceAll(input, "\r", "")
var n yaml.Node
err := yaml.Unmarshal([]byte(input), &n)
if err != nil {
Expand Down