Skip to content

Commit

Permalink
Fixes an off by one error in getting location in withinclause (#500)
Browse files Browse the repository at this point in the history
Hit in particular when the match extends to the end of the file.
  • Loading branch information
gfs authored Aug 11, 2022
1 parent d7bf96f commit bf9bb5f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions AppInspector.RulesEngine/OatExtensions/WithinOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public OperationResult WithinOperationDelegate(Clause c, object? state1, object?
if (wc.SameLineOnly)
{
var startInner = tc.LineStarts[tc.GetLocation(boundary.Index).Line];
var endInner = tc.LineEnds[tc.GetLocation(startInner + boundary.Length).Line];
var endInner = tc.LineEnds[tc.GetLocation(startInner + (boundary.Length - 1)).Line];
return new Boundary()
{
Index = startInner,
Expand All @@ -72,12 +72,11 @@ public OperationResult WithinOperationDelegate(Clause c, object? state1, object?
// Before is already a negative number
var startInner = tc.LineStarts[Math.Max(1, startLine + wc.Before)];
var endInner = tc.LineEnds[Math.Min(tc.LineEnds.Count - 1, startLine + wc.After)];
var bound = new Boundary()
return new Boundary()
{
Index = startInner,
Length = (endInner - startInner) + 1
};
return bound;
}

if (wc.SameFile)
Expand Down

0 comments on commit bf9bb5f

Please sign in to comment.