Skip to content

SHOULD throw if extension attributes are NOT following naming convention? #380

@c-pius

Description

@c-pius

Describe the Bug
Extension attributes NOT following the naming convention (lowercase) are added to the event (no error thrown) but their value is added as undefined.

Steps to Reproduce
Use the following snippet:

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

Check the resulting event:

{
  //...
  id: '0815',
  specversion: '1.0',
  type: 'my.event.type',
  source: 'my.event.source',
  foo: undefined
}

Expected Behavior
I assume according to spec an error should be thrown if attributes not following the naming convention are passed. Alternatively, if they are still accepted, their value should be passed on to the event correctly.

Additional context
If decided to still pass the extension attribute, I think the problem lies somewhere here:

eventObj[header.substring(CONSTANTS.EXTENSIONS_PREFIX.length)] = headers[header];

header has been sanitized (converted to lowercase, e.g. ce-foo) which is not present as such in the headers object (still original casing, e.g. ce-FOO) and therefore undefined is set as value.

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