Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public interface BaggageBuilder {
/**
* Adds the key/value pair and metadata regardless of whether the key is present.
*
* <p>Per the <a href="https://www.w3.org/TR/baggage/#definition">W3C Baggage spec</a>, a
* baggage-name must be a non-empty token. Calls with a {@code null} or empty {@code key}, a
* {@code null} {@code value}, or a {@code null} {@code entryMetadata} are silently ignored.
*
* @param key the {@code String} key which will be set.
* @param value the {@code String} value to set for the given key.
* @param entryMetadata the {@code BaggageEntryMetadata} metadata to set for the given key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static class Builder implements BaggageBuilder {

@Override
public BaggageBuilder put(String key, String value, BaggageEntryMetadata entryMetadata) {
if ((key == null) || (value == null) || (entryMetadata == null)) {
if ((key == null) || key.isEmpty() || (value == null) || (entryMetadata == null)) {
return this;
}
data.add(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,17 @@ void put_keyUnprintableChars() {
@Test
void put_keyEmpty() {
BaggageBuilder builder = ONE_ENTRY.toBuilder();
Baggage built = builder.build();
builder.put("", "value");
assertThat(builder.build().getEntryValue("")).isEqualTo("value");
assertThat(builder.build()).isEqualTo(built);
}

@Test
void put_keyEmpty_withMetadata() {
BaggageBuilder builder = ONE_ENTRY.toBuilder();
Baggage built = builder.build();
builder.put("", "value", TMD);
assertThat(builder.build()).isEqualTo(built);
}

@Test
Expand Down
Loading