diff --git a/hcl/scanner/scanner.go b/hcl/scanner/scanner.go index c9b40677..87bd5049 100644 --- a/hcl/scanner/scanner.go +++ b/hcl/scanner/scanner.go @@ -399,6 +399,13 @@ func (s *Scanner) scanHeredoc() { return } + // Ignore the '\r' in Windows line endings + if ch == '\r' { + if s.peek() == '\n' { + ch = s.next() + } + } + // If we didn't reach a newline then that is also not good if ch != '\n' { s.err("invalid characters in heredoc anchor") diff --git a/hcl/scanner/scanner_test.go b/hcl/scanner/scanner_test.go index 7c4eb5b8..b497a9fa 100644 --- a/hcl/scanner/scanner_test.go +++ b/hcl/scanner/scanner_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/hashicorp/hcl/hcl/token" + "strings" ) var f100 = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" @@ -308,6 +309,44 @@ func TestFloat(t *testing.T) { testTokenList(t, tokenLists["float"]) } +func TestWindowsLineEndings(t *testing.T) { + hcl := `// This should have Windows line endings +resource "aws_instance" "foo" { + user_data=<