mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Fixed: Handle download clients sending invalid content-type header.
DownloadStation incorrectly surrounds charset with double-quotes. whereas the http standard specifies they must be without quotes. fixes #1586
This commit is contained in:
parent
7f8093de92
commit
8d776abb48
42
src/NzbDrone.Common.Test/Http/HttpHeaderFixture.cs
Normal file
42
src/NzbDrone.Common.Test/Http/HttpHeaderFixture.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Test.Http
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class HttpHeaderFixture : TestBase
|
||||||
|
{
|
||||||
|
[TestCase("text/html; charset=\"utf-8\"", "utf-8")]
|
||||||
|
[TestCase("text/html; charset=utf-8", "utf-8")]
|
||||||
|
public void should_get_encoding_from_content_type_header(string contentType, string charsetExpected)
|
||||||
|
{
|
||||||
|
var headers = new NameValueCollection();
|
||||||
|
|
||||||
|
headers.Add("Content-Type", contentType);
|
||||||
|
|
||||||
|
var httpheader = new HttpHeader(headers);
|
||||||
|
|
||||||
|
httpheader.GetEncodingFromContentType().Should().Be(Encoding.GetEncoding(charsetExpected));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("text/html; charset=asdasd")]
|
||||||
|
public void should_throw_when_invalid_encoding_is_in_content_type_header(string contentType)
|
||||||
|
{
|
||||||
|
var headers = new NameValueCollection();
|
||||||
|
|
||||||
|
headers.Add("Content-Type", contentType);
|
||||||
|
|
||||||
|
var httpheader = new HttpHeader(headers);
|
||||||
|
|
||||||
|
Action action = () => httpheader.GetEncodingFromContentType();
|
||||||
|
action.ShouldThrow<ArgumentException>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -84,6 +84,7 @@
|
|||||||
<Compile Include="ExtensionTests\IEnumerableExtensionTests\IntersectByFixture.cs" />
|
<Compile Include="ExtensionTests\IEnumerableExtensionTests\IntersectByFixture.cs" />
|
||||||
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
|
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
|
||||||
<Compile Include="Http\HttpClientFixture.cs" />
|
<Compile Include="Http\HttpClientFixture.cs" />
|
||||||
|
<Compile Include="Http\HttpHeaderFixture.cs" />
|
||||||
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
||||||
<Compile Include="Http\HttpRequestFixture.cs" />
|
<Compile Include="Http\HttpRequestFixture.cs" />
|
||||||
<Compile Include="Http\HttpUriFixture.cs" />
|
<Compile Include="Http\HttpUriFixture.cs" />
|
||||||
|
@ -145,7 +145,7 @@ public static Encoding GetEncodingFromContentType(string contentType)
|
|||||||
|
|
||||||
if (charset.IsNotNullOrWhiteSpace())
|
if (charset.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
encoding = Encoding.GetEncoding(charset);
|
encoding = Encoding.GetEncoding(charset.Replace("\"", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user