mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 03:16:11 +00:00
Fix null reference access when ContentType is null (#2501)
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user