From 665d74b45daba6c9a67643896f87c212ebe0e453 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Tue, 1 Dec 2015 12:09:13 -0500 Subject: [PATCH] Fix scanner for Windows line endings and add tests --- hcl/scanner/scanner.go | 7 +++++++ hcl/scanner/scanner_test.go | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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=<