Skip to content

Commit

Permalink
fixed parsing nested object with the value of an unquoted string, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gurkankaymak committed Dec 23, 2022
1 parent 896f9c2 commit 67c3b38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ func (p *parser) extractObject(isSubObject ...bool) (Object, error) {
}
}

if parenthesisBalanced && len(isSubObject) > 0 && isSubObject[0] {
return object, nil
}

for currentRow := p.scanner.Line; currentRow == lastRow && p.scanner.TokenText() != ""; currentRow = p.scanner.Line {
concatenated, err := p.checkAndConcatenate(object, key)
if err != nil {
Expand All @@ -356,6 +352,10 @@ func (p *parser) extractObject(isSubObject ...bool) (Object, error) {
}
}

if parenthesisBalanced && len(isSubObject) > 0 && isSubObject[0] {
return object, nil
}

for p.scanner.TokenText() == commentToken {
p.consumeComment()
}
Expand Down
8 changes: 8 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ func TestExtractObject(t *testing.T) {
assertDeepEqual(t, got, Object{"a": Object{"b": Int(1)}, "c": Int(2)})
})

t.Run("extract nested object with the value of unquoted string", func(t *testing.T) {
parser := newParser(strings.NewReader("x {a.b:10cc}"))
parser.advance()
got, err := parser.extractObject()
assertNoError(t, err)
assertDeepEqual(t, got, Object{"x": Object{"a": Object{"b": concatenation{Int(10), String(""), String("cc")}}}})
})

t.Run("skip the comments inside objects", func(t *testing.T) {
config := `{
# this is a comment
Expand Down

0 comments on commit 67c3b38

Please sign in to comment.