Skip to content

Commit

Permalink
null check HttpContext in SystemWebVersionLocator (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Aug 31, 2022
1 parent 6cdca90 commit 8c54be0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Skip attachment if stream is empty ([#1854](https://github.com/getsentry/sentry-dotnet/pull/1854))
- Allow some mobile options to be modified from defaults ([#1857](https://github.com/getsentry/sentry-dotnet/pull/1857))
- Fix environment name casing issue ([#1861](https://github.com/getsentry/sentry-dotnet/pull/1861))
- Null check HttpContext in SystemWebVersionLocator ([#1881](https://github.com/getsentry/sentry-dotnet/pull/1881))

## 3.20.1

Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.AspNet/Internal/SystemWebVersionLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Sentry.AspNet.Internal;

internal static class SystemWebVersionLocator
{
internal static string? Resolve(string? release, HttpContext context)
internal static string? Resolve(string? release, HttpContext? context)
{
if (!string.IsNullOrWhiteSpace(release))
{
Expand All @@ -15,9 +15,9 @@ internal static class SystemWebVersionLocator
return Resolve(context);
}

internal static string? Resolve(HttpContext context)
internal static string? Resolve(HttpContext? context)
{
if (context.ApplicationInstance?.GetType() is { } type)
if (context?.ApplicationInstance?.GetType() is { } type)
{
// Usually the type is ASP.global_asax and the BaseType is the Web Application.
while (type is { Namespace: "ASP" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public void GetCurrent_GetEntryAssemblyNull_HttpApplicationAssembly()
Assert.Equal(expected, actual);
}

[Fact]
public void Null_HttpContext()
{
var actual = SystemWebVersionLocator.Resolve((string)null, null);

Assert.Null(actual);
}

[Fact]
public void HttpApplicationAssembly_VersionParsing()
{
Expand Down

0 comments on commit 8c54be0

Please sign in to comment.