Skip to content

Commit ba06d91

Browse files
committed
Merge branch '1.5.x' into 1.6.x
2 parents 487d99a + 742eef4 commit ba06d91

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

micrometer-tracing-bridges/micrometer-tracing-bridge-brave/src/main/java/io/micrometer/tracing/brave/bridge/W3CPropagation.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,19 @@ List<AbstractMap.SimpleEntry<Baggage, String>> addBaggageToContext(String baggag
254254
if (beginningOfMetadata > 0) {
255255
entry = entry.substring(0, beginningOfMetadata);
256256
}
257-
String[] keyAndValue = entry.split("=");
258-
if (keyAndValue.length % 2 == 0) {
259-
for (int i = 0; i < keyAndValue.length - 1; i += 2) {
260-
try {
261-
String key = keyAndValue[i].trim();
262-
String value = keyAndValue[i + 1].trim();
263-
Baggage baggage = this.braveBaggageManager.createBaggage(key);
264-
pairs.add(new AbstractMap.SimpleEntry<>(baggage, value));
265-
}
266-
catch (Exception e) {
267-
if (log.isDebugEnabled()) {
268-
log.debug("Exception occurred while trying to parse baggage with key value "
269-
+ Arrays.toString(keyAndValue) + ". Will ignore that entry.", e);
270-
}
257+
String[] keyAndValue = entry.split("=", 2);
258+
boolean hasValue = keyAndValue.length == 2 && !keyAndValue[1].isEmpty();
259+
if (hasValue) {
260+
try {
261+
String key = keyAndValue[0].trim();
262+
String value = keyAndValue[1].trim();
263+
Baggage baggage = this.braveBaggageManager.createBaggage(key);
264+
pairs.add(new AbstractMap.SimpleEntry<>(baggage, value));
265+
}
266+
catch (Exception e) {
267+
if (log.isDebugEnabled()) {
268+
log.debug("Exception occurred while trying to parse baggage with key value "
269+
+ Arrays.toString(keyAndValue) + ". Will ignore that entry.", e);
271270
}
272271
}
273272
}

micrometer-tracing-bridges/micrometer-tracing-bridge-brave/src/test/java/io/micrometer/tracing/brave/bridge/W3CBaggagePropagatorTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ void extract_keyValuesNotinPairBaggageHeader() {
114114
assertThat(baggageEntries(contextWithBaggage)).containsExactly(entry("a", "b"));
115115
}
116116

117+
@Test
118+
// gh-1350
119+
void extract_valueWithEquals() {
120+
TraceContextOrSamplingFlags context = context();
121+
Map<String, String> carrier = new HashMap<>();
122+
carrier.put("baggage", "key=value=with=equals");
123+
124+
TraceContextOrSamplingFlags contextWithBaggage = propagator.contextWithBaggage(carrier, context, Map::get);
125+
126+
Map<String, String> baggageEntries = baggageEntries(contextWithBaggage);
127+
assertThat(baggageEntries).hasSize(1).containsEntry("key", "value=with=equals");
128+
}
129+
117130
@Test
118131
void extract_singleEntry() {
119132
TraceContextOrSamplingFlags context = context();

0 commit comments

Comments
 (0)