Skip to content

Commit

Permalink
MB-32987 - Fix handling of nested arrays of various objs and types, a…
Browse files Browse the repository at this point in the history
…nd to keep parsing once embedded objs are done
  • Loading branch information
nelio2k committed Feb 8, 2019
1 parent 21fbf48 commit 3a0c03f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
19 changes: 13 additions & 6 deletions fastMatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,11 @@ func (m *FastMatcher) matchObjectOrArray(token tokenType, tokenData []byte, node
}

switch token {
case endToken:
case tknObjectEnd:
return nil, false
case tknArrayEnd:
return nil, false
case tknEnd:
return nil, true
case tknListDelim:
arrayIndex++
Expand All @@ -643,6 +647,7 @@ func (m *FastMatcher) matchObjectOrArray(token tokenType, tokenData []byte, node
if err != nil {
return err, true
}
// Keep this here to catch any empty array or empty objs
if token == endToken {
return nil, true
}
Expand All @@ -656,12 +661,14 @@ func (m *FastMatcher) matchObjectOrArray(token tokenType, tokenData []byte, node
case tknEscString:
keyBytes = keyLitParse.ParseEscString(tokenData)
case tknArrayStart:
fallthrough
// Do nothing
case tknObjectStart:
// In case of embedded objects or arrays
return m.matchExec(token, tokenData, node), false
// Do nothing
default:
panic(fmt.Sprintf("expected literal, received: %v", token))
// If it's an array, it's possible that we're grabbing a literal like int or float, and we should not panic
if !arrayMode {
panic(fmt.Sprintf("expected literal, received: %v", token))
}
}

if arrayMode {
Expand All @@ -674,7 +681,7 @@ func (m *FastMatcher) matchObjectOrArray(token tokenType, tokenData []byte, node
}

if token != tknObjectKeyDelim {
panic("expected object key delimiter")
panic(fmt.Sprintf("expected object key delimiter: got %v, %v", token, string(tokenData)))
}

token, tokenData, err = m.tokens.Step()
Expand Down
27 changes: 27 additions & 0 deletions filterExprParser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,33 @@ func TestFilterExpressionParser(t *testing.T) {
_, err = GetFilterExpressionMatcher(testStr)
assert.Nil(err)

// MB-32987 - some combinations of nested arrays and objects tests
fe = &FilterExpression{}
err = parser.ParseString("achievements[0] = 49 AND achievements[1] = 58 AND achievements[2] = 108 AND arrOfObjs[0].`1D` = 50 AND floatArrs[0] = 1.1", fe)
assert.Nil(err)
expr, err = fe.OutputExpression()
assert.Nil(err)
matchDef = trans.Transform([]Expression{expr})
assert.NotNil(matchDef)
m = NewFastMatcher(matchDef)
userData = map[string]interface{}{
"category": 1,
"email": "[email protected]",
"city": "258171",
"name": "25134e ced17f",
"coins": 354.32,
"alt_email": "[email protected]",
"body": "testBody",
"achievements": [6]int{49, 58, 108, 141, 177, 229},
"floatArrs": [6]float64{1.1, 2.2, 3.3, 4.4, 5.5, 6.6},
"arrOfObjs": [1]map[string]interface{}{{"1D": 50}},
"nestedArr": [1][2]int{{61, 62}},
"realm": "f41e4a",
}
udMarsh, _ = json.Marshal(userData)
match, err = m.Match(udMarsh)
assert.True(match)

// Negative
_, _, err = NewFilterExpressionParser("fieldpath.`path = fieldPath2")
assert.NotNil(err)
Expand Down

0 comments on commit 3a0c03f

Please sign in to comment.