Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Dropped obsolete regexes
  • Loading branch information
jamescrosswell committed Jul 23, 2025
commit 0223cf9716f8fb118dc7c4277ea02c85d36f076c
22 changes: 9 additions & 13 deletions src/Sentry/Extensibility/StringStackTraceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,22 @@ public partial class StringStackTraceFactory : ISentryStackTraceFactory

#if NET9_0_OR_GREATER
[GeneratedRegex(FullStackTraceLinePattern)]
private static partial Regex FullStackTraceLine { get; }
#elif NET8_0
private static readonly Regex FullStackTraceLine = FullStackTraceLineRegex();

[GeneratedRegex(FullStackTraceLinePattern)]
private static partial Regex FullStackTraceLineRegex();
internal static partial Regex FullStackTraceLine { get; }
#else
private static readonly Regex FullStackTraceLine = new (FullStackTraceLinePattern, RegexOptions.Compiled);
internal static readonly Regex FullStackTraceLine = FullStackTraceLineRegex();

[GeneratedRegex(FullStackTraceLinePattern)]
private static partial Regex FullStackTraceLineRegex();
#endif

#if NET9_0_OR_GREATER
[GeneratedRegex(StackTraceLinePattern)]
private static partial Regex StackTraceLine { get; }
#elif NET8_0
private static readonly Regex StackTraceLine = StackTraceLineRegex();

[GeneratedRegex(StackTraceLinePattern)]
private static partial Regex StackTraceLineRegex();
#else
private static readonly Regex StackTraceLine = new (StackTraceLinePattern, RegexOptions.Compiled);
private static readonly Regex StackTraceLine = StackTraceLineRegex();

[GeneratedRegex(StackTraceLinePattern)]
private static partial Regex StackTraceLineRegex();
#endif

/// <summary>
Expand Down
26 changes: 25 additions & 1 deletion test/Sentry.Tests/Internals/StringStackTraceFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Stack trace filters out Sentry frames by namespace
namespace Other.Tests.Internals;

#if PLATFORM_NEUTRAL
#if PLATFORM_NEUTRAL && NET8_0_OR_GREATER

public class StringStackTraceFactoryTests
{
Expand Down Expand Up @@ -37,6 +37,30 @@ public Task MethodGeneric()
[MethodImpl(MethodImplOptions.NoInlining)]
private static void GenericMethodThatThrows<T>(T value) =>
throw new Exception();

[Theory]
[InlineData("at MyNamespace.MyClass.MyMethod in /path/to/file.cs:line 42", "MyNamespace", "MyClass.MyMethod", "/path/to/file.cs", "42")]
[InlineData("at Foo.Bar.Baz in C:\\code\\foo.cs:line 123", "Foo", "Bar.Baz", "C:\\code\\foo.cs", "123")]
public void FullStackTraceLine_ValidInput_Matches(
string input, string expectedModule, string expectedFunction, string expectedFile, string expectedLine)
{
var match = StringStackTraceFactory.FullStackTraceLine.Match(input);
Assert.True(match.Success);
Assert.Equal(expectedModule, match.Groups["Module"].Value);
Assert.Equal(expectedFunction, match.Groups["Function"].Value);
Assert.Equal(expectedFile, match.Groups["FileName"].Value);
Assert.Equal(expectedLine, match.Groups["LineNo"].Value);
}

[Theory]
[InlineData("at MyNamespace.MyClass.MyMethod +")]
[InlineData("random text")]
[InlineData("at . in :line ")]
public void FullStackTraceLine_InvalidInput_DoesNotMatch(string input)
{
var match = StringStackTraceFactory.FullStackTraceLine.Match(input);
Assert.False(match.Success);
}
}

#endif
Loading