Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null check HttpContext in SystemWebVersionLocator #1881

Merged
merged 4 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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