Skip to content

Commit

Permalink
Merge pull request #29 from Stillpoint-Software/develop
Browse files Browse the repository at this point in the history
[BUG]: SelectExpressionFactory fails with empty string (#28)
MattEdwardsWaggleBee authored Jul 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 97d69cb + 1dc2ece commit f645e59
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ static class ExpressionHelper<TNode>

public static Expression GetExpression( ReadOnlySpan<char> item, FilterContext<TNode> context )
{
if ( item.IsEmpty )
return null;

if ( item[0] != '$' && item[0] != '@' )
return null;

38 changes: 38 additions & 0 deletions test/Hyperbee.Json.Tests/Query/JsonPathFilterExpressionTests.cs
Original file line number Diff line number Diff line change
@@ -489,6 +489,44 @@ public void FilterExpressionWithEqualsArrayWithSingleQuotes( string query, Type
_ = source.Select( query ).ToArray();
}

[DataTestMethod]
[DataRow( "$[?(@.a[?(@.price>10)])]", typeof( JsonDocument ) )]
[DataRow( "$[?(@.a[?(@.price>10)])]", typeof( JsonNode ) )]
[ExpectedException( typeof( NotSupportedException ) )]
public void FilterExpressionWithSubFilter( string query, Type sourceType )
{
// consensus: NOT_SUPPORTED

var json =
"""
[
{
"a": [{"price": 1}, {"price": 3}]
},
{
"a": [{"price": 11}]
},
{
"a": [{"price": 8}, {"price": 12}, {"price": 3}]
},
{
"a": []
}
]
""";

var source = GetDocumentFromSource( sourceType, json );

var matches = source.Select( query );
var expected = new[]
{
source.FromJsonPathPointer( "$[1]" ),
source.FromJsonPathPointer( "$[2]" )
};

Assert.IsTrue( expected.SequenceEqual( matches ) );
}

[DataTestMethod]
[DataRow( "$[?((@.key<44)==false)]", typeof( JsonDocument ) )]
[DataRow( "$[?((@.key<44)==false)]", typeof( JsonNode ) )]

0 comments on commit f645e59

Please sign in to comment.