From 7db87c281a514fb2909418d451b343ba96419499 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 20 Nov 2025 17:45:25 -0800 Subject: [PATCH] [API] Parse baggage value as spec compliant --- api/include/opentelemetry/baggage/baggage.h | 4 ++-- api/test/baggage/baggage_test.cc | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) 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 {",", {}, {}}, {",=,", {}, {}},