Skip to content

Commit dc390a6

Browse files
lachmattCodeBlanch
andauthored
[api-baggage] revert space encoding change (#5687)
Co-authored-by: Mikel Blanchard <[email protected]>
1 parent 28824f8 commit dc390a6

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/OpenTelemetry.Api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
* **Breaking change:** Revert space character encoding change from `+` to `%20`
6+
for baggage item values from [#5303](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5303)
7+
([#5687](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5687))
8+
59
## 1.9.0-rc.1
610

711
Released 2024-Jun-07

src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
using System.Net;
45
using System.Text;
56
using OpenTelemetry.Internal;
67

@@ -93,7 +94,7 @@ public override void Inject<T>(PropagationContext context, T carrier, Action<T,
9394
continue;
9495
}
9596

96-
baggage.Append(Uri.EscapeDataString(item.Key)).Append('=').Append(Uri.EscapeDataString(item.Value)).Append(',');
97+
baggage.Append(WebUtility.UrlEncode(item.Key)).Append('=').Append(WebUtility.UrlEncode(item.Value)).Append(',');
9798
}
9899
while (e.MoveNext() && ++itemCount < MaxBaggageItems && baggage.Length < MaxBaggageLength);
99100
baggage.Remove(baggage.Length - 1, 1);
@@ -140,8 +141,8 @@ internal static bool TryExtractBaggage(string[] baggageCollection, out Dictionar
140141
continue;
141142
}
142143

143-
var key = Uri.UnescapeDataString(parts[0]);
144-
var value = Uri.UnescapeDataString(parts[1]);
144+
var key = WebUtility.UrlDecode(parts[0]);
145+
var value = WebUtility.UrlDecode(parts[1]);
145146

146147
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
147148
{

test/OpenTelemetry.Api.Tests/Trace/Propagation/BaggagePropagatorTest.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ public void ValidateSpecialCharsBaggageExtraction()
131131
Assert.Equal("key%28%293", escapedKey);
132132
Assert.Equal("value%28%29%21%26%3B%3A", escapedValue);
133133

134-
var initialBaggage =
135-
$"key%201=value%201,{encodedKey}={encodedValue},{escapedKey}={escapedValue},key4=%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~";
136-
134+
var initialBaggage = $"key+1=value+1,{encodedKey}={encodedValue},{escapedKey}={escapedValue}";
137135
var carrier = new List<KeyValuePair<string, string>>
138136
{
139137
new KeyValuePair<string, string>(BaggagePropagator.BaggageHeaderName, initialBaggage),
@@ -144,11 +142,11 @@ public void ValidateSpecialCharsBaggageExtraction()
144142
Assert.False(propagationContext == default);
145143
Assert.True(propagationContext.ActivityContext == default);
146144

147-
Assert.Equal(4, propagationContext.Baggage.Count);
145+
Assert.Equal(3, propagationContext.Baggage.Count);
148146

149147
var actualBaggage = propagationContext.Baggage.GetBaggage();
150148

151-
Assert.Equal(4, actualBaggage.Count);
149+
Assert.Equal(3, actualBaggage.Count);
152150

153151
Assert.True(actualBaggage.ContainsKey("key 1"));
154152
Assert.Equal("value 1", actualBaggage["key 1"]);
@@ -158,10 +156,6 @@ public void ValidateSpecialCharsBaggageExtraction()
158156

159157
Assert.True(actualBaggage.ContainsKey("key()3"));
160158
Assert.Equal("value()!&;:", actualBaggage["key()3"]);
161-
162-
// x20-x7E range
163-
Assert.True(actualBaggage.ContainsKey("key4"));
164-
Assert.Equal(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", actualBaggage["key4"]);
165159
}
166160

167161
[Fact]
@@ -201,14 +195,11 @@ public void ValidateSpecialCharsBaggageInjection()
201195
{
202196
{ "key 1", "value 1" },
203197
{ "key2", "!x_x,x-x&x(x\");:" },
204-
205-
// x20-x7E range
206-
{ "key3", " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" },
207198
}));
208199

209200
this.baggage.Inject(propagationContext, carrier, Setter);
210201

211202
Assert.Single(carrier);
212-
Assert.Equal("key%201=value%201,key2=%21x_x%2Cx-x%26x%28x%22%29%3B%3A,key3=%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~", carrier[BaggagePropagator.BaggageHeaderName]);
203+
Assert.Equal("key+1=value+1,key2=!x_x%2Cx-x%26x(x%22)%3B%3A", carrier[BaggagePropagator.BaggageHeaderName]);
213204
}
214205
}

0 commit comments

Comments
 (0)