Skip to content

Unable to deserialize data_base64 non escaped string #1128

@ivan-penchev

Description

@ivan-penchev

Context

I am working with a service that consumes CloudEvents produced by another service using the CloudEvents .NET SDK.

The issue arises with the data_base64 field in the messages produced by the second service. Specifically, this field contains the character sequence \u002B, which represents the + character. According to the specification RFC4648, the backslash character (\) is not permitted, leading to potential parsing errors.

Upon encountering this issue, I reported it to the CloudEvents C# SDK repository. In response, John Skeet clarified that the use of \u002B to represent the + character is a valid encoding method within JSON, and the + itself is indeed a valid character according to RFC4648.

This suggests that the handling or decoding of such sequences needs to be managed correctly by the consuming application or library.

Steps to reproduce

// simplified event based on jskeet input
jsonData := `{
	    "specversion": "1.0",
	    "id": "00716a6e-6063-43d3-8717-66888f060055",
	    "source": "urn:aws-global:7777",
	    "type": "updated.v1",
	    "datacontenttype": "application/octet-stream",
	    "data_base64": "\\u002B\\u002B\\u002B\\u002B"
	}`

var eventWithBase64Data cloudevents.Event
if err := json.Unmarshal([]byte(jsonData), &eventWithBase64Data); err != nil {
	slog.Error("Failed to unmarshal cloudevent JSON", err)
}

/// output:
/// ERROR Failed to unmarshal cloudevent JSON !BADKEY="illegal base64 data at input byte 0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions