Skip to content
Open
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
4 changes: 2 additions & 2 deletions QueryKit.UnitTests/PropertyResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
var input = """FirstName == "Ann" || Title == "s" """;
var config = new QueryKitConfiguration(config =>
{
config.Property<TestingPerson>(x => x.Title).PreventFilter();

Check warning on line 32 in QueryKit.UnitTests/PropertyResolverTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.
});

var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
Expand All @@ -43,8 +43,8 @@
var input = """(Title, FirstName) == "x" || Age > 100""";
var config = new QueryKitConfiguration(config =>
{
config.Property<TestingPerson>(x => x.Title).PreventFilter();

Check warning on line 46 in QueryKit.UnitTests/PropertyResolverTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.
config.Property<TestingPerson>(x => x.FirstName).PreventFilter();

Check warning on line 47 in QueryKit.UnitTests/PropertyResolverTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.
});

var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
Expand Down Expand Up @@ -89,7 +89,7 @@
var config = new QueryKitConfiguration(config =>
{
config.IgnoredClauseBehavior = IgnoredClauseBehavior.Remove;
config.Property<TestingPerson>(x => x.Rating).PreventFilter();

Check warning on line 92 in QueryKit.UnitTests/PropertyResolverTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.
});

var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
Expand Down Expand Up @@ -119,8 +119,8 @@
var config = new QueryKitConfiguration(config =>
{
config.IgnoredClauseBehavior = IgnoredClauseBehavior.Remove;
config.Property<TestingPerson>(x => x.Title).PreventFilter();

Check warning on line 122 in QueryKit.UnitTests/PropertyResolverTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.
config.Property<TestingPerson>(x => x.FirstName).PreventFilter();

Check warning on line 123 in QueryKit.UnitTests/PropertyResolverTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.
});

var filterExpression = FilterParser.ParseFilter<TestingPerson>(input, config);
Expand Down Expand Up @@ -555,7 +555,7 @@
}

[Fact]
public void alias_replacement_replaces_a_query_name_in_a_nested_path()
public void alias_replacement_does_not_replace_a_query_name_in_a_nested_path()
{
var config = new QueryKitConfiguration(config =>
{
Expand All @@ -564,7 +564,7 @@

var input = config.PropertyMappings.ReplaceAliasesWithPropertyPaths("""Author.Name == "x" && name == "y" """);

input.Should().Be("""Author.Title == "x" && Title == "y" """);
input.Should().Be("""Author.Name == "x" && Title == "y" """);
}

[Fact]
Expand Down
5 changes: 3 additions & 2 deletions QueryKit/QueryKitPropertyMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ public string ReplaceAliasesWithPropertyPaths(string input)
{
// Use regular expression to isolate left side of the expression. Query names and
// operators are matched literally, so escape any regex metacharacters they contain
// (e.g. the `^` in `^^` would otherwise be read as a start-of-line anchor).
var regex = AliasRegexCache.Get($@"\b{Regex.Escape(queryKitPropertyInfo.QueryName!)}\b(?=\s*{Regex.Escape(op)})");
// (e.g. the `^` in `^^` would otherwise be read as a start-of-line anchor). A query name
// after a dot is a segment of a nested path, so it is not replaced.
var regex = AliasRegexCache.Get($@"(?<!\.)\b{Regex.Escape(queryKitPropertyInfo.QueryName!)}\b(?=\s*{Regex.Escape(op)})");

if (queryKitPropertyInfo is { CanSort: false, CanFilter: false} && regex.IsMatch(input))
{
Expand Down
Loading