Skip to content

Commit

Permalink
functions/stdlib: formatdate to correctly handle literals at the end …
Browse files Browse the repository at this point in the history
…of the format string
  • Loading branch information
OwenTuz authored Oct 5, 2020
1 parent 36785d4 commit 4cc7873
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cty/function/stdlib/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,14 @@ func splitDateFormat(data []byte, atEOF bool) (advance int, token []byte, err er
for i := 1; i < len(data); i++ {
if data[i] == esc {
if (i + 1) == len(data) {
// We need at least one more byte to decide if this is an
// escape or a terminator.
return 0, nil, nil
if atEOF {
// We have a closing quote and are at the end of our input
return len(data), data, nil
} else {
// We need at least one more byte to decide if this is an
// escape or a terminator.
return 0, nil, nil
}
}
if data[i+1] == esc {
i++ // doubled-up quotes are an escape sequence
Expand Down
5 changes: 5 additions & 0 deletions cty/function/stdlib/datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func TestFormatDate(t *testing.T) {
cty.StringVal("3 o'clock PM"),
``,
},
{
cty.StringVal("H 'o''clock'"),
cty.StringVal("3 o'clock"),
``,
},
{
cty.StringVal("hh:mm:ssZZZZ"),
cty.StringVal("15:04:05+0000"),
Expand Down

0 comments on commit 4cc7873

Please sign in to comment.