Skip to content

Commit

Permalink
Verify %1 on filter expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurvdv committed Jan 8, 2024
1 parent ea9ffc5 commit 3c411ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Design/Rule0050SetFilterOperatorCharInFilterExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols;
using System.Collections.Immutable;
using System.Text.RegularExpressions;

namespace BusinessCentral.LinterCop.Design
{
Expand Down Expand Up @@ -39,6 +40,11 @@ private void CheckParameter(IOperation operand, ref IInvocationExpression operat
return;

string parameterString = operand.Syntax.ToFullString();

string pattern = @"%\d+"; // Only when a %1 is used in the filter expression the unsupported operators are threaded as a literal character
Regex regex = new Regex(pattern);
if (!regex.IsMatch(parameterString)) return;

foreach (char unsupportedOperator in unsupportedOperators)
{
ctx.CancellationToken.ThrowIfCancellationRequested();
Expand Down
6 changes: 3 additions & 3 deletions LinterCopAnalyzers.resx
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,12 @@
<value>SourceTable property not defined on {0} '{1}'.</value>
</data>
<data name="Rule0050SetFilterOperatorCharInFilterExpressionTitle" xml:space="preserve">
<value>Operator '{0}' found in filter expression, currently treated as a literal character. Implement StrSubstNo() to apply '{0}' as operator.</value>
<value>Operator '{0}' found in filter expression, currently treated as a literal character. Implement StrSubstNo() to apply as operator.</value>
</data>
<data name="Rule0050SetFilterOperatorCharInFilterExpressionFormat" xml:space="preserve">
<value>Operator '{0}' found in filter expression, currently treated as a literal character. Implement StrSubstNo() to apply '{0}' as operator.</value>
<value>Operator '{0}' found in filter expression, currently treated as a literal character. Implement StrSubstNo() to apply as operator.</value>
</data>
<data name="Rule0050SetFilterOperatorCharInFilterExpressionDescription" xml:space="preserve">
<value>Operator '{0}' found in filter expression, currently treated as a literal character. Implement StrSubstNo() to apply '{0}' as operator.</value>
<value>Operator '{0}' found in filter expression, currently treated as a literal character. Implement StrSubstNo() to apply as operator.</value>
</data>
</root>

0 comments on commit 3c411ac

Please sign in to comment.