Skip to content

Commit

Permalink
disallow empty string for baggage name (#1484)
Browse files Browse the repository at this point in the history
spec 1.36.0 clarifies that empty string is not a valid baggage name
  • Loading branch information
brettmc authored Jan 29, 2025
1 parent e3f77b7 commit 420b5ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/API/Baggage/BaggageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function remove(string $key): BaggageBuilderInterface
/** @inheritDoc */
public function set(string $key, $value, ?MetadataInterface $metadata = null): BaggageBuilderInterface
{
if ($key === '') {
return $this;
}
$metadata ??= Metadata::getEmpty();

$this->entries[$key] = new Entry($value, $metadata);
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/API/Baggage/BaggageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,11 @@ public function test_get_all(): void
);
}

public function test_empty_name_disallowed(): void
{
$baggage = Baggage::getBuilder()->set('', 'bar')->build();
$this->assertTrue($baggage->isEmpty());
}

// endregion
}

0 comments on commit 420b5ef

Please sign in to comment.