Skip to content

Commit 8d3da7d

Browse files
committed
Reject "data" as the name of an extension attribute
This isn't currently in the CloudEvents spec, but was agreed at the meeting of 2022-02-03, on the grounds that the most prominent event formt - JSON - already *implicitly* prohibits it. We should wait until the spec is updated before merging this. Signed-off-by: Jon Skeet <[email protected]>
1 parent 409982e commit 8d3da7d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/CloudNative.CloudEvents/CloudEventAttribute.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using CloudNative.CloudEvents.Core;
66
using System;
7+
using System.Collections.Generic;
78

89
namespace CloudNative.CloudEvents
910
{
@@ -15,6 +16,12 @@ namespace CloudNative.CloudEvents
1516
/// </summary>
1617
public class CloudEventAttribute
1718
{
19+
private static readonly IList<string> ReservedNames = new List<string>
20+
{
21+
CloudEventsSpecVersion.SpecVersionAttributeName,
22+
"data"
23+
};
24+
1825
/// <summary>
1926
/// The type of the attribute. All values provided must be compatible with this.
2027
/// </summary>
@@ -60,7 +67,7 @@ public static CloudEventAttribute CreateExtension(string name, CloudEventAttribu
6067
{
6168
Validation.CheckNotNull(name, nameof(name));
6269
Validation.CheckNotNull(type, nameof(type));
63-
if (name == CloudEventsSpecVersion.SpecVersionAttributeName)
70+
if (ReservedNames.Contains(name))
6471
{
6572
throw new ArgumentException($"The attribute name '{name}' is reserved and cannot be used for an extension attribute.");
6673
}

test/CloudNative.CloudEvents.UnitTests/CloudEventAttributeTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public void CreateExtension_SpecVersionName() =>
7878
Assert.Throws<ArgumentException>(() =>
7979
CloudEventAttribute.CreateExtension(CloudEventsSpecVersion.SpecVersionAttributeName, CloudEventAttributeType.String));
8080

81+
[Fact]
82+
public void CreateExtension_DataName() =>
83+
Assert.Throws<ArgumentException>(() =>
84+
CloudEventAttribute.CreateExtension("data", CloudEventAttributeType.String));
85+
8186
[Fact]
8287
public void Validate_NoValidator_Valid()
8388
{

0 commit comments

Comments
 (0)