Skip to content

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

Open

Description

@c-pius

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

Activity

  1. lance commented on Mar 5, 2021

    @lance
    Member

    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: "".

  2. github-actions commented on Apr 5, 2021

    @github-actions
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions