1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00

Fixed: Parsing headers that have a trailing semi-colon (#1117)

This commit is contained in:
Mitchell Cash 2017-03-11 13:27:26 +10:00 committed by Devin Buhl
parent 149c5292f1
commit 3b3fe197ca
2 changed files with 15 additions and 2 deletions

View File

@ -5,6 +5,7 @@
using System.Text;
using NzbDrone.Common.Http;
using System.Collections.Specialized;
using System.Linq;
namespace NzbDrone.Common.Test.Http
{
@ -36,5 +37,17 @@ public void should_throw_when_invalid_encoding_is_in_content_type_header(string
Action action = () => httpheader.GetEncodingFromContentType();
action.ShouldThrow<ArgumentException>();
}
[Test]
public void should_parse_cookie_with_trailing_semi_colon()
{
var cookies = HttpHeader.ParseCookies("uid=123456; pass=123456b2f3abcde42ac3a123f3f1fc9f;");
cookies.Count.Should().Be(2);
cookies.First().Key.Should().Be("uid");
cookies.First().Value.Should().Be("123456");
cookies.Last().Key.Should().Be("pass");
cookies.Last().Value.Should().Be("123456b2f3abcde42ac3a123f3f1fc9f");
}
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Specialized;
@ -169,7 +169,7 @@ public static DateTime ParseDateTime(string value)
public static List<KeyValuePair<string, string>> ParseCookies(string cookies)
{
return cookies.Split(';')
return cookies.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
.Select(v => v.Trim().Split('='))
.Select(v => new KeyValuePair<string, string>(v[0], v[1]))
.ToList();