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

Validate new Members only once, when they are added to the Baggage #2505

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions baggage/baggage.go
Expand Up @@ -222,15 +222,11 @@ type Member struct {
properties properties
}

// NewMember returns a new Member from the passed arguments. An error is
// returned if the created Member would be invalid according to the W3C
// Baggage specification.
// NewMember returns a new Member from the passed arguments. To avoid double
// validation, the created member is not validated yet. It will be when it's
// added to the baggage.
func NewMember(key, value string, props ...Property) (Member, error) {
m := Member{key: key, value: value, properties: properties(props).Copy()}
if err := m.validate(); err != nil {
return Member{}, err
}

return m, nil
}

Expand Down
2 changes: 1 addition & 1 deletion baggage/baggage_test.go
Expand Up @@ -669,7 +669,7 @@ func TestMemberValidation(t *testing.T) {

func TestNewMember(t *testing.T) {
m, err := NewMember("", "")
assert.ErrorIs(t, err, errInvalidKey)
assert.NoError(t, err)
assert.Equal(t, Member{}, m)

key, val := "k", "v"
Expand Down