Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 199b0fa

Browse files
author
Nate McMaster
committed
Require CookieBuilder.Name to be a not null or empty
1 parent 271faf1 commit 199b0fa

File tree

3 files changed

+57
-55
lines changed

3 files changed

+57
-55
lines changed

src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using Microsoft.AspNetCore.Http.Abstractions;
56

67
namespace Microsoft.AspNetCore.Http
78
{
@@ -10,10 +11,18 @@ namespace Microsoft.AspNetCore.Http
1011
/// </summary>
1112
public class CookieBuilder
1213
{
14+
private string _name;
15+
1316
/// <summary>
1417
/// The name of the cookie.
1518
/// </summary>
16-
public virtual string Name { get; set; }
19+
public virtual string Name
20+
{
21+
get => _name;
22+
set => _name = !string.IsNullOrEmpty(value)
23+
? value
24+
: throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(value));
25+
}
1726

1827
/// <summary>
1928
/// The cookie path.

src/Microsoft.AspNetCore.Http.Abstractions/Properties/Resources.Designer.cs

Lines changed: 44 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.AspNetCore.Http.Abstractions/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,7 @@
153153
<data name="Exception_UseMiddlewareExplicitArgumentsNotSupported" xml:space="preserve">
154154
<value>Types that implement '{0}' do not support explicit arguments.</value>
155155
</data>
156+
<data name="ArgumentCannotBeNullOrEmpty" xml:space="preserve">
157+
<value>Argument cannot be null or empty.</value>
158+
</data>
156159
</root>

0 commit comments

Comments
 (0)