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

pull/2/head
Mitchell Cash 8 years ago committed by Devin Buhl
parent 149c5292f1
commit 3b3fe197ca

@ -5,6 +5,7 @@ using System;
using System.Text;
using NzbDrone.Common.Http;
using System.Collections.Specialized;
using System.Linq;
namespace NzbDrone.Common.Test.Http
{
@ -36,5 +37,17 @@ namespace NzbDrone.Common.Test.Http
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");
}
}
}

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Specialized;
@ -169,7 +169,7 @@ namespace NzbDrone.Common.Http
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();

Loading…
Cancel
Save