From ba6e74ce47d8beea65234150a0fb68149e4ad42c Mon Sep 17 00:00:00 2001 From: Fawaz Dinnunhan <39809217+fawazd@users.noreply.github.com> Date: Thu, 30 Apr 2020 05:41:06 +1200 Subject: [PATCH] Fixed conditions in comments passing bug - conditions no longer pass if there are only matches in comments (#155) --- DevSkim-DotNet/Microsoft.DevSkim/TextContainer.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/DevSkim-DotNet/Microsoft.DevSkim/TextContainer.cs b/DevSkim-DotNet/Microsoft.DevSkim/TextContainer.cs index 8ed2f42c..5e20ad5e 100644 --- a/DevSkim-DotNet/Microsoft.DevSkim/TextContainer.cs +++ b/DevSkim-DotNet/Microsoft.DevSkim/TextContainer.cs @@ -64,8 +64,19 @@ public bool MatchPattern(SearchPattern pattern, Boundary boundary, SearchConditi string text = _content.Substring(scope.Index, scope.Length); List matches = MatchPattern(pattern, text); - if (matches.Count > 0) - result = true; + + foreach (Boundary match in matches) + { + Boundary translatedBoundary = new Boundary() + { + Length = match.Length, + Index = match.Index + scope.Index + }; + if (ScopeMatch(pattern, translatedBoundary)) + { + result = true; + } + } return result; }