diff --git a/CHANGELOG.md b/CHANGELOG.md index 22a42e23dd..2f26d93a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ Increment the: * [CONFIGURATION] File configuration - rename tls properties [#3805](https://github.com/open-telemetry/opentelemetry-cpp/pull/3805) +* [API] Parse baggage value as spec compliant + [#3758](https://github.com/open-telemetry/opentelemetry-cpp/pull/3758) + Breaking changes: * [CONFIGURATION] File configuration - remove zipkin diff --git a/api/include/opentelemetry/baggage/baggage.h b/api/include/opentelemetry/baggage/baggage.h index 6c799cda27..e3e08ff225 100644 --- a/api/include/opentelemetry/baggage/baggage.h +++ b/api/include/opentelemetry/baggage/baggage.h @@ -274,8 +274,13 @@ class OPENTELEMETRY_EXPORT Baggage { ret.push_back(' '); } - else if (std::isalnum(str[i]) || str[i] == '-' || str[i] == '_' || str[i] == '.' || - str[i] == '~') + // See https://www.w3.org/TR/baggage/#definition + else if ((str[i] >= '!') /* 21 */ + && (str[i] <= '~') /* 7E */ + && (str[i] != '"') /* 22 */ + && (str[i] != ',') /* 2C */ + && (str[i] != ';') /* 3B */ + && (str[i] != '\\')) /* 5C */ { ret.push_back(str[i]); } diff --git a/api/test/baggage/baggage_test.cc b/api/test/baggage/baggage_test.cc index 526c813022..be7b4ccdf4 100644 --- a/api/test/baggage/baggage_test.cc +++ b/api/test/baggage/baggage_test.cc @@ -71,6 +71,8 @@ TEST(BaggageTest, ValidateExtractHeader) {"1a-2f%40foo=bar%251,a%2A%2Ffoo-_%2Fbar=bar+4", {"1a-2f@foo", "a*/foo-_/bar"}, {"bar%1", "bar 4"}}, // decoding is done properly + {"field=foo:bar", {"field"}, {"foo:bar"}}, // colon in value + {"mixed=a/b:c?d=e", {"mixed"}, {"a/b:c?d=e"}}, // mixed special characters {"k1=v1,invalidmember,k2=v2", {"k1", "k2"}, {"v1", "v2"}}, // invalid member is skipped {",", {}, {}}, {",=,", {}, {}},