Skip to content
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
17 changes: 15 additions & 2 deletions QueryKit.UnitTests/PropertyResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ public void property_prevented_for_filter_and_sort_is_removed_by_its_member_name
}

[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 @@ -866,7 +866,20 @@ public void alias_replacement_replaces_a_query_name_in_a_nested_path()

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]
public void filter_with_a_query_name_in_a_nested_path_resolves_the_nested_path()
{
var config = new QueryKitConfiguration(config =>
{
config.Property<Recipe>(x => x.Title).HasQueryName("name");
});

var filterExpression = FilterParser.ParseFilter<Recipe>("""Author.Name == "x" """, config);

filterExpression.ToDisplayString().Should().Be("""x => (x.Author.Name == "x")""");
}

[Fact]
Expand Down
5 changes: 3 additions & 2 deletions QueryKit/QueryKitPropertyMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,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 stays.
var regex = AliasRegexCache.Get($@"(?<!\.)\b{Regex.Escape(queryKitPropertyInfo.QueryName!)}\b(?=\s*{Regex.Escape(op)})");

input = regex.Replace(input, propertyPath);
}
Expand Down
Loading