diff --git a/src/Http/Http/test/RequestCookiesCollectionTests.cs b/src/Http/Http/test/RequestCookiesCollectionTests.cs index d2648435af6d..fa3fb6d67f74 100644 --- a/src/Http/Http/test/RequestCookiesCollectionTests.cs +++ b/src/Http/Http/test/RequestCookiesCollectionTests.cs @@ -29,4 +29,29 @@ public void ParseManyCookies() Assert.Equal(12, cookies.Count); } + + [Theory] + [InlineData(",", null)] + [InlineData(";", null)] + [InlineData("er=dd,cc,bb", new[] { "dd" })] + [InlineData("er=dd,err=cc,errr=bb", new[] { "dd", "cc", "bb" })] + [InlineData("errorcookie=dd,:(\"sa;", new[] { "dd" })] + [InlineData("s;", null)] + public void ParseInvalidCookies(string cookieToParse, string[] expectedCookieValues) + { + var cookies = RequestCookieCollection.Parse(new StringValues(new[] { cookieToParse })); + + if(expectedCookieValues == null) + { + Assert.Equal(0, cookies.Count); + return; + } + + Assert.Equal(expectedCookieValues.Length, cookies.Count); + for (int i = 0; i < expectedCookieValues.Length; i++) + { + var value = expectedCookieValues[i]; + Assert.Equal(value, cookies.ElementAt(i).Value); + } + } } diff --git a/src/Http/Shared/CookieHeaderParserShared.cs b/src/Http/Shared/CookieHeaderParserShared.cs index 2e2b3d67beac..e558ec1e4dc4 100644 --- a/src/Http/Shared/CookieHeaderParserShared.cs +++ b/src/Http/Shared/CookieHeaderParserShared.cs @@ -28,6 +28,13 @@ public static bool TryParseValues(StringValues values, IDictionary