Skip to content
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

SHOULD throw if subject is empty string (parsed from structured content mode)? #382

Open
c-pius opened this issue Feb 10, 2021 · 2 comments

Comments

@c-pius
Copy link

c-pius commented Feb 10, 2021

Describe the Bug
Spec states that the subject MUST be a non-empty string. In structured content mode HTTP.toEvent adds an empty subject string as undefined to the event and calling validate on the resulting event does therefore NOT throw.

In binary content mode, HTTP.toEvent adds the empty subject as subject: '' and a subsequent call on validate throws subject should NOT be shorter than 1 characters. This would be the correct behavior I assume.

Steps to Reproduce
Use the following snippet:

const event = HTTP.toEvent({
  headers: {
    'Content-Type': 'application/cloudevents+json'
  },
  body: {
    id: '0815',
    specversion: '1.0',
    type: 'my.event.type',
    source: 'my.event.source',
    subject: ''
  }
})

// event has subject: undefined

event.validate() // does not throw

Expected Behavior
event should have subject: '' and event.validate() should throw.

Additional context

property is the empty string here and therefore the parser is not executed

In general not sure if this should be an error on HTTP.toEvent already or only at validate

@lance
Copy link
Member

lance commented Mar 5, 2021

event should have subject: '' and event.validate() should throw.

Hmm, since subject is an optional attribute, it seems odd to throw if it's empty - even if the spec states that it should be a non-empty string. I would argue that the binary parser is wrong, and that it should not throw when receiving a header such as ce-subject: "".

@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2021

This issue is stale because it has been open 30 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants