Skip to content

Commit

Permalink
Sanitize localized stack trace in exception tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstv committed Apr 28, 2021
1 parent 6f5d492 commit 91edb9c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions UnitTests/BugReporter.Tests/SerializableExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ private static string Sanitize(string exceptionMessage)
StringBuilder m = new();
foreach (string line in exceptionMessage.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
{
Match match = Regex.Match(line, @".*(?<path>\sin\s.*)");
string sanitizedLine = Regex.Replace(line, "^ --- .* ---$", " --- End of inner exception stack trace ---");
sanitizedLine = Regex.Replace(sanitizedLine, @"^ \w+ ", " at ");

Match match = Regex.Match(sanitizedLine, @".*(?<path>\sin\s.*)");
if (match.Success)
{
m.AppendLine(line.Replace(match.Groups["path"].Value, string.Empty));
}
else
{
m.AppendLine(line);
sanitizedLine = sanitizedLine.Replace(match.Groups["path"].Value, string.Empty);
}

m.AppendLine(sanitizedLine);
}

return m.ToString();
Expand Down

0 comments on commit 91edb9c

Please sign in to comment.