Fix null reference access when ContentType is null (#2501)

This commit is contained in:
Diogo Rolo
2022-07-21 22:36:02 +01:00
committed by GitHub
parent cc56183da8
commit 4f4ef5ba73
2 changed files with 12 additions and 1 deletions
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
#if !NO_SERIALIZABLE
@@ -141,6 +142,16 @@ namespace Octokit.Tests.Exceptions
Assert.NotNull(stringRepresentation);
}
[Fact]
public void DoesNotThrowIfContentTypeIsNotDefined()
{
var response = CreateResponse(HttpStatusCode.GatewayTimeout, null, new Dictionary<string, string>(), null);
var exception = new ApiException(response);
var stringRepresentation = exception.ToString();
Assert.NotNull(stringRepresentation);
}
[Fact]
public void DoesNotPrintImageContent()
{
+1 -1
View File
@@ -200,7 +200,7 @@ namespace Octokit
{
get
{
return HttpResponse != null
return HttpResponse?.ContentType != null
&& !HttpResponse.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)
&& HttpResponse.Body is string
? (string)HttpResponse.Body : string.Empty;