Skip to content

Commit 6792609

Browse files
committed
Fix string interpolation bug and rename variable
- Fix ${regex} to {regex} in log message (was outputting literal text) - Rename CaseSensitiveFunctions to CaseInsensitiveCapableFunctions - Add test for IndexOfMatch with invalid regex in Compile()
1 parent 3c4bccb commit 6792609

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/Serilog.Expressions/Expressions/Compilation/Text/TextMatchingTransformer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Expression TryCompileIndexOfMatch(bool ignoreCase, Expression corpus, Expression
6666
}
6767
}
6868

69-
SelfLog.WriteLine($"Serilog.Expressions: `IndexOfMatch()` requires a constant string regular expression argument; found ${regex}.");
69+
SelfLog.WriteLine($"Serilog.Expressions: `IndexOfMatch()` requires a constant string regular expression argument; found {regex}.");
7070
return new CallExpression(false, Operators.OpUndefined);
7171
}
7272
}

src/Serilog.Expressions/Expressions/Compilation/Validation/ExpressionValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ExpressionValidator : IdentityTransformer
2626
readonly List<string> _errors = new();
2727

2828
// Functions that support case-insensitive operations (have StringComparison parameter)
29-
static readonly HashSet<string> CaseSensitiveFunctions = new(StringComparer.OrdinalIgnoreCase)
29+
static readonly HashSet<string> CaseInsensitiveCapableFunctions = new(StringComparer.OrdinalIgnoreCase)
3030
{
3131
// String operations
3232
Operators.OpContains,
@@ -103,7 +103,7 @@ protected override Expression Transform(CallExpression call)
103103
}
104104

105105
// Check for invalid CI modifier usage
106-
if (call.IgnoreCase && !CaseSensitiveFunctions.Contains(call.OperatorName))
106+
if (call.IgnoreCase && !CaseInsensitiveCapableFunctions.Contains(call.OperatorName))
107107
{
108108
_errors.Add($"The function `{call.OperatorName}` does not support case-insensitive operation.");
109109
}

test/Serilog.Expressions.Tests/ExpressionValidationTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public void CompileMethodStillThrowsForInvalidExpressions()
115115

116116
Assert.Throws<ArgumentException>(() =>
117117
SerilogExpression.Compile("Length(Name) ci"));
118+
119+
Assert.Throws<ArgumentException>(() =>
120+
SerilogExpression.Compile("IndexOfMatch(Text, '(?<')"));
118121
}
119122

120123
[Theory]

0 commit comments

Comments
 (0)