Repository navigation
[API] Percent-encode spaces in Baggage::ToHeader - #4765
Open
hidingmyname wants to merge 3 commits into
Open
hidingmyname wants to merge 3 commits into
hidingmyname wants to merge 3 commits into
Conversation
Baggage::ToHeader encoded a space as '+' (form-style), which the W3C Baggage specification does not define; other implementations read it as a literal '+'. Encode spaces as %20 instead. Existing C++ readers already decode %20, so this is safe across versions. Decoding of '+' as space is intentionally left unchanged. Part of open-telemetry#4745
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4765 +/- ##
==========================================
- Coverage 86.61% 86.61% -0.00%
==========================================
Files 530 530
Lines 21169 21167 -2
==========================================
- Hits 18333 18331 -2
Misses 2836 2836
🚀 New features to boost your workflow:
|
mateenali66
approved these changes
Nov 7, 2026
mateenali66
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks for the fix.
ValidateInjectHeader and SpaceIsPercentEncoded fail with the + branch put back and pass at 7aa97087, and + still decodes as a space.
See minor comment on the CHANGELOG link.
Co-authored-by: Mateen Anjum <mateenali66@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4745
Changes
Baggage::ToHeaderencoded a space in keys/values as+(form-style). The W3C Baggage specification uses percent-encoding, and other OpenTelemetry implementations read+as a literal plus sign, so a value such ashello worldarrived ashello+worldon non-C++ receivers.This PR changes only the encode side: a space is now emitted as
%20(it simply falls through to the existing percent-encoding branch). As noted in the issue triage, this is safe across versions because existing C++ readers already decode%20.The decode side is intentionally unchanged:
FromHeaderstill decodes+as a space, so headers from older C++ senders keep reading the same way. Whether to stop treating+as a space is left as a maintainer decision; I'm happy to follow up with a separate PR for that if wanted.Tests (
api/test/baggage/baggage_test.cc):ValidateInjectHeader: expected headers updated from+to%20.ValidateExtractHeader: still asserts+decodes to a space; added a case that%20decodes to a space.SpaceIsPercentEncoded:Set("k", "hello world")->ToHeader()isk=hello%20worldand round-trips throughFromHeader.Verification (GCC 15.3, CMake + Ninja, Debug):
baggage_test12 passed, 2 failed (ValidateInjectHeader,SpaceIsPercentEncoded, which gotk=hello+world).baggage_test14/14,baggage_propagator_test6/6,composite_propagator_test2/2,global_propagator_test3/3,propagator_builders_test11/11 passed.CHANGELOG.mdupdated for non-trivial changes