Skip to content

Commit

Permalink
handle the case where the comment contains "'" character, fixes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
gurkankaymak committed Nov 8, 2022
1 parent fc42959 commit e0e27a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ func (p *parser) extractSubstitution() (*Substitution, error) {
}

func (p *parser) consumeComment() {
for token := p.scanner.Peek(); token != '\n' && token != scanner.EOF; token = p.scanner.Peek() {
for token := p.scanner.Peek(); token != '\n' && token != scanner.EOF && !strings.HasSuffix(p.scanner.TokenText(), "\n"); token = p.scanner.Peek() {
p.advance()
}
p.advance()
Expand Down
12 changes: 12 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ func TestExtractObject(t *testing.T) {
assertDeepEqual(t, got, Object{"name": String("value")})
})

t.Run("should parse properly if the comment contains a `'` character (which results golang scanner to append `\n` to the latest token instead of a separate token)", func(t *testing.T) {
config := `
# it's a comment
name: value
`
parser := newParser(strings.NewReader(config))
parser.advance()
got, err := parser.extractObject()
assertNoError(t, err)
assertDeepEqual(t, got, Object{"name": String("value")})
})

t.Run("return missingCommaError if there is no comma or ASCII newline between the object elements", func(t *testing.T) {
parser := newParser(strings.NewReader("{a:1 b:2}"))
parser.advance()
Expand Down

0 comments on commit e0e27a6

Please sign in to comment.