Skip to content

Commit 6977113

Browse files
authored
fix: creating an event does not error when the event attribute name is too long (#593)
* fix: creating an event does not error when the event attribute name is too long * From the spec, the requirement for the length of attribute names is only a SHOULD, not a MUST. Currently, if the length is over 20 then the sdk throws an error, which I believe is incorrect because the length requirement is not a MUST. Signed-off-by: Calum Murray <cmurray@redhat.com> * fix(test): test expects not to throw Signed-off-by: Calum Murray <cmurray@redhat.com> --------- Signed-off-by: Calum Murray <cmurray@redhat.com>
1 parent 154e913 commit 6977113

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: src/event/cloudevent.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ export class CloudEvent<T = undefined> implements CloudEventV1<T> {
109109

110110
// finally process any remaining properties - these are extensions
111111
for (const [key, value] of Object.entries(properties)) {
112-
// Extension names should only allow lowercase a-z and 0-9 in the name
112+
// Extension names must only allow lowercase a-z and 0-9 in the name
113113
// names should not exceed 20 characters in length
114-
if (!key.match(/^[a-z0-9]{1,20}$/) && strict) {
114+
if (!key.match(/^[a-z0-9]+$/) && strict) {
115115
throw new ValidationError(`invalid extension name: ${key}
116116
CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z')
117117
or digits ('0' to '9') from the ASCII character set. Attribute names SHOULD

Diff for: test/integration/cloud_event_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ describe("A CloudEvent", () => {
8282
}).throw("invalid extension name");
8383
});
8484

85-
it("Throw a validation error for invalid extension names, more than 20 chars", () => {
85+
it("Not throw a validation error for invalid extension names, more than 20 chars", () => {
8686
expect(() => {
8787
new CloudEvent({ "123456789012345678901": "extension1", ...fixture });
88-
}).throw("invalid extension name");
88+
}).not.throw("invalid extension name");
8989
});
9090

9191
it("Throws a validation error for invalid uppercase extension names", () => {

0 commit comments

Comments
 (0)