Skip to content

fix: do not modify incoming event's specversion #419

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 1 commit into from
May 25, 2021

Conversation

lance
Copy link
Member

@lance lance commented May 21, 2021

Even if the specversion is totally invalid, we should not change the valuereceived in an incoming Message. Previously we defaulted to 1.0 if we did not recognize the version number. This commit changes that, leaving the value unmodified. We default to parsing this mystery event with the 1.0 spec. When the event is validated with event.validate() we return false.

One additional small change to eliminate a prettier warning about pasrer being previously declared.

As discussed in #332 this same problem exists for both id and time. However, I am not addressing these at the moment. I think we should simply reconsider ANY defaults. Regarding id and time, the behavior is different with each. With id missing, it is not possible to parse an incoming Message, since we use the ID to determine if it's a structured event. With no id present, it's just not an event. The spec states that you determine whether an incoming HTTP request is a structured cloud event by checking for ce-id in the headers. So... 🤷

Regarding time, it's not currently possible to construct an event that does NOT have a time property. When using the new CloudEvent() constructor, a default value is created if one isn't provided. However, event objects are read only, so setting event.time = undefined after the fact doesn't work. If instead, we accept the incoming message, create an event, check to see if the original message had a time attribute, and if not use event.cloneWith({ time: undefined }) - we're right back where we started, since cloneWith() uses the constructor internally.

Given that, I think the only answer is for us to remove the default value generated for time.

Fixes: #332
Fixes: #333

Signed-off-by: Lance Ball [email protected]

Even if the specversion is totally invalid, we should not change the value
received in an incoming `Message`. Previously we defaulted to 1.0 if we did
not recognize the version number. This commit changes that, leaving the value
unmodified. We default to parsing this mystery event with the 1.0 spec. When
the event is validated with `event.validate()` we return `false`.

One additional small change to eliminate a prettier warning about `parer`
being previously declared.

Fixes: cloudevents#332
Fixes: cloudevents#333

Signed-off-by: Lance Ball <[email protected]>
@lance lance added type/fix A change that fixes something that is broken module/lib Related to the main source code labels May 21, 2021
@lance lance requested a review from a team May 21, 2021 16:29
@lance lance self-assigned this May 21, 2021
@lance lance merged commit 22e42dd into cloudevents:main May 25, 2021
@lance lance deleted the lance/332-specversion branch May 25, 2021 15:10
lholmquist pushed a commit to lholmquist/sdk-javascript that referenced this pull request Jul 6, 2021
Even if the specversion is totally invalid, we should not change the value
received in an incoming `Message`. Previously we defaulted to 1.0 if we did
not recognize the version number. This commit changes that, leaving the value
unmodified. We default to parsing this mystery event with the 1.0 spec. When
the event is validated with `event.validate()` we return `false`.

One additional small change to eliminate a prettier warning about `parer`
being previously declared.

Fixes: cloudevents#332
Fixes: cloudevents#333

Signed-off-by: Lance Ball <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/lib Related to the main source code type/fix A change that fixes something that is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid doing console.error Should throw if specversion attribute is missing
2 participants