diff --git a/api/include/opentelemetry/baggage/baggage.h b/api/include/opentelemetry/baggage/baggage.h index 6c799cda27..5478117c23 100644 --- a/api/include/opentelemetry/baggage/baggage.h +++ b/api/include/opentelemetry/baggage/baggage.h @@ -274,8 +274,8 @@ class OPENTELEMETRY_EXPORT Baggage { ret.push_back(' '); } - else if (std::isalnum(str[i]) || str[i] == '-' || str[i] == '_' || str[i] == '.' || - str[i] == '~') + else if (str[i] >= ' ' && str[i] <= '~' && str[i] != '"' && str[i] != ',' && str[i] != ';' && + str[i] != '\\') { 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 {",", {}, {}}, {",=,", {}, {}},