Skip to content

Commit 5225ab8

Browse files
authored
[API] Parse baggage value as spec compliant (#3758)
1 parent f33dcc0 commit 5225ab8

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Increment the:
2121
* [CONFIGURATION] File configuration - rename tls properties
2222
[#3805](https://github.com/open-telemetry/opentelemetry-cpp/pull/3805)
2323

24+
* [API] Parse baggage value as spec compliant
25+
[#3758](https://github.com/open-telemetry/opentelemetry-cpp/pull/3758)
26+
2427
Breaking changes:
2528

2629
* [CONFIGURATION] File configuration - remove zipkin

api/include/opentelemetry/baggage/baggage.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,13 @@ class OPENTELEMETRY_EXPORT Baggage
274274
{
275275
ret.push_back(' ');
276276
}
277-
else if (std::isalnum(str[i]) || str[i] == '-' || str[i] == '_' || str[i] == '.' ||
278-
str[i] == '~')
277+
// See https://www.w3.org/TR/baggage/#definition
278+
else if ((str[i] >= '!') /* 21 */
279+
&& (str[i] <= '~') /* 7E */
280+
&& (str[i] != '"') /* 22 */
281+
&& (str[i] != ',') /* 2C */
282+
&& (str[i] != ';') /* 3B */
283+
&& (str[i] != '\\')) /* 5C */
279284
{
280285
ret.push_back(str[i]);
281286
}

api/test/baggage/baggage_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ TEST(BaggageTest, ValidateExtractHeader)
7171
{"1a-2f%40foo=bar%251,a%2A%2Ffoo-_%2Fbar=bar+4",
7272
{"1a-2f@foo", "a*/foo-_/bar"},
7373
{"bar%1", "bar 4"}}, // decoding is done properly
74+
{"field=foo:bar", {"field"}, {"foo:bar"}}, // colon in value
75+
{"mixed=a/b:c?d=e", {"mixed"}, {"a/b:c?d=e"}}, // mixed special characters
7476
{"k1=v1,invalidmember,k2=v2", {"k1", "k2"}, {"v1", "v2"}}, // invalid member is skipped
7577
{",", {}, {}},
7678
{",=,", {}, {}},

0 commit comments

Comments
 (0)