Skip to content

Commit b9a6d3e

Browse files
committed
fix parsing an operator from a string if the value is a special character
1 parent 6b3cf85 commit b9a6d3e

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/romaklayt.DynamicFilter.Common/Extensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ public static class Extensions
1010
{
1111
private const string DefaultValue = @"\default";
1212

13-
internal static string GetOperator(this string filter, string firstElement, string secondElement) => RemoveSubstring(RemoveSubstring(filter, firstElement), secondElement);
13+
internal static string GetOperator(this string filter, string firstElement, string secondElement) => RemoveSubstring(RemoveSubstring(filter, firstElement), secondElement, true);
1414

15-
private static string RemoveSubstring(string sourceString, string removeString)
15+
private static string RemoveSubstring(string sourceString, string removeString, bool reverse = false)
1616
{
17-
var index = sourceString.IndexOf(removeString, StringComparison.InvariantCulture);
17+
var index = reverse ? sourceString.LastIndexOf(removeString, StringComparison.Ordinal) : sourceString.IndexOf(removeString, StringComparison.Ordinal);
1818
return index < 0 ? sourceString : sourceString.Remove(index, removeString.Length);
1919
}
2020

2121
internal static List<FilterArrayLogicOperatorEnum> ParseOperators(string filterArray, IEnumerable<string> split)
2222
{
23-
var op = split.Aggregate(filterArray, RemoveSubstring).Where(c => c != '(' && c != ')' && c != ' ').Select(c => c.ToString()).ToList();
23+
var op = split.Aggregate(filterArray, (s, s1) => RemoveSubstring(s, s1)).Where(c => c != '(' && c != ')' && c != ' ').Select(c => c.ToString()).ToList();
2424
var operatorTemp = string.Empty;
2525
var operators = new List<FilterArrayLogicOperatorEnum>();
2626
foreach (var s in op)

0 commit comments

Comments
 (0)