Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(visitor): unconsumed rbrace in (*traverser).decodeObject() #654

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ast/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (self *traverser) decodeObject() error {

/* check for empty object */
if self.parser.s[self.parser.p] == '}' {
self.parser.p++
return self.visitor.OnObjectEnd()
}

Expand Down Expand Up @@ -326,6 +327,6 @@ func (self *traverser) decodeString(iv int64, ep int) error {
return self.visitor.OnString(out)
}

// If visitor return this error on `OnObjectBegin()` or `OnArrayBegin()`,
// If visitor return this error on `OnObjectBegin()` or `OnArrayBegin()`,
// the transverer will skip entiry object or array
var VisitOPSkip = errors.New("")
31 changes: 19 additions & 12 deletions ast/visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ import (
`github.com/stretchr/testify/require`
)

var visitorTestCases = []struct {
name string
jsonStr string
} {
{"default", _TwitterJson},
{"issue_case01", "[1193.6419677734375]"},
{"issue653", `{"v0": 0, "m0": {}, "v1": 1, "a0": [], "v2": 2}`},
}

type visitorNodeDiffTest struct {
t *testing.T
str string
Expand Down Expand Up @@ -328,12 +337,11 @@ func TestVisitor_NodeDiff(t *testing.T) {
return writer
}

t.Run("default", func(t *testing.T) {
suite.Run(t, _TwitterJson, newTracer(t))
})
t.Run("issue_case01", func(t *testing.T) {
suite.Run(t, `[1193.6419677734375]`, newTracer(t))
})
for _, c := range visitorTestCases {
t.Run(c.name, func(t *testing.T) {
suite.Run(t, c.jsonStr, newTracer(t))
})
}
}

type visitorUserNode interface {
Expand Down Expand Up @@ -640,12 +648,11 @@ func TestVisitor_UserNodeDiff(t *testing.T) {
var d1 visitorUserNodeASTDecoder
var d2 visitorUserNodeVisitorDecoder

t.Run("default", func(t *testing.T) {
testUserNodeDiff(t, &d1, &d2, _TwitterJson)
})
t.Run("issue_case01", func(t *testing.T) {
testUserNodeDiff(t, &d1, &d2, `[1193.6419677734375]`)
})
for _, c := range visitorTestCases {
t.Run(c.name, func(t *testing.T) {
testUserNodeDiff(t, &d1, &d2, c.jsonStr)
})
}
}

type skipVisitor struct {
Expand Down
Loading