From 6977113d7b49bd2b702632cc09e29cc0c003e2a1 Mon Sep 17 00:00:00 2001 From: Calum Murray Date: Mon, 22 Jul 2024 13:22:43 -0400 Subject: [PATCH 1/2] 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 * fix(test): test expects not to throw Signed-off-by: Calum Murray --------- Signed-off-by: Calum Murray --- src/event/cloudevent.ts | 4 ++-- test/integration/cloud_event_test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/event/cloudevent.ts b/src/event/cloudevent.ts index 4da7075a..16c722b8 100644 --- a/src/event/cloudevent.ts +++ b/src/event/cloudevent.ts @@ -109,9 +109,9 @@ export class CloudEvent implements CloudEventV1 { // 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 diff --git a/test/integration/cloud_event_test.ts b/test/integration/cloud_event_test.ts index f45a6f68..84472070 100644 --- a/test/integration/cloud_event_test.ts +++ b/test/integration/cloud_event_test.ts @@ -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", () => { From 8357719babc6b04acb819e5e706e3f08aa40bd1e Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Mon, 22 Jul 2024 13:26:06 -0400 Subject: [PATCH 2/2] chore(main): release 8.0.2 (#594) Signed-off-by: Lucas Holmquist --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3a81ba5..dac6d56e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.2](https://github.com/cloudevents/sdk-javascript/compare/v8.0.1...v8.0.2) (2024-07-22) + + +### Bug Fixes + +* creating an event does not error when the event attribute name is too long ([#593](https://github.com/cloudevents/sdk-javascript/issues/593)) ([6977113](https://github.com/cloudevents/sdk-javascript/commit/6977113d7b49bd2b702632cc09e29cc0c003e2a1)) + ## [8.0.1](https://github.com/cloudevents/sdk-javascript/compare/v8.0.0...v8.0.1) (2024-06-12) diff --git a/package-lock.json b/package-lock.json index a6140d35..e3002512 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cloudevents", - "version": "8.0.1", + "version": "8.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cloudevents", - "version": "8.0.1", + "version": "8.0.2", "license": "Apache-2.0", "dependencies": { "ajv": "^8.11.0", diff --git a/package.json b/package.json index 0237eeea..b1dc715d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cloudevents", - "version": "8.0.1", + "version": "8.0.2", "description": "CloudEvents SDK for JavaScript", "main": "dist/index.js", "scripts": {