Skip to content

Commit

Permalink
Merge pull request #245 from octo/cartridge-return
Browse files Browse the repository at this point in the history
scanner: Improve regular expression in "scanner".scanHeredoc().
  • Loading branch information
mitchellh authored Apr 3, 2018
2 parents f40e974 + 25340db commit c247bd0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions hcl/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func TestFormatValidOutput(t *testing.T) {
cases := []string{
"#\x00",
"#\ue123t",
"Y=<<4\n4/\n\n\n/4/@=4/\n\n\n/4000000004\r\r\n00004\n",
"x=<<_\n_\r\r\n_\n",
}

for _, c := range cases {
Expand Down
1 change: 1 addition & 0 deletions hcl/printer/testdata/object_with_heredoc.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
obj {
foo = [<<EOF
TEXT!
!!EOF
EOF
]
}
1 change: 1 addition & 0 deletions hcl/printer/testdata/object_with_heredoc.input
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
obj {
foo = [<<EOF
TEXT!
!!EOF
EOF
]
}
4 changes: 2 additions & 2 deletions hcl/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ func (s *Scanner) scanHeredoc() {

var identRegexp *regexp.Regexp
if identBytes[0] == '-' {
identRegexp = regexp.MustCompile(fmt.Sprintf(`[[:space:]]*%s\z`, identBytes[1:]))
identRegexp = regexp.MustCompile(fmt.Sprintf(`^[[:space:]]*%s\r*\z`, identBytes[1:]))
} else {
identRegexp = regexp.MustCompile(fmt.Sprintf(`[[:space:]]*%s\z`, identBytes))
identRegexp = regexp.MustCompile(fmt.Sprintf(`^[[:space:]]*%s\r*\z`, identBytes))
}

// Read the actual string value
Expand Down

0 comments on commit c247bd0

Please sign in to comment.