Skip to content

fix: creating an event does not error when the event attribute name is too long #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/event/cloudevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export class CloudEvent<T = undefined> implements CloudEventV1<T> {

// finally process any remaining properties - these are extensions
for (const [key, value] of Object.entries(properties)) {
// Extension names should only allow lowercase a-z and 0-9 in the name
// Extension names must only allow lowercase a-z and 0-9 in the name
// names should not exceed 20 characters in length
if (!key.match(/^[a-z0-9]{1,20}$/) && strict) {
if (!key.match(/^[a-z0-9]+$/) && strict) {
throw new ValidationError(`invalid extension name: ${key}
CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z')
or digits ('0' to '9') from the ASCII character set. Attribute names SHOULD
Expand Down
4 changes: 2 additions & 2 deletions test/integration/cloud_event_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ describe("A CloudEvent", () => {
}).throw("invalid extension name");
});

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

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