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

[BUG]: SelectExpressionFactory fails with empty string (#28) #29

Merged
merged 1 commit into from
Jul 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 38 additions & 0 deletions test/Hyperbee.Json.Tests/Query/JsonPathFilterExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )]
Expand Down
Loading