Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ private void putBaggage(
if (entriesAdded >= maxEntries) {
return;
}
String decodedValue = decodeValue(value);
metadataValue = decodeValue(metadataValue);
String decodedValue;
try {
decodedValue = decodeValue(value);
metadataValue = decodeValue(metadataValue);
} catch (IllegalArgumentException e) {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be good to log a warning here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this, but left it unchanged since the current parsing behavior appears to favor ignoring invalid baggage and continuing. Happy to update this if logging is preferred.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the current parsing behavior to throw an exception on invalid baggage?

IMO adding a warning level log about invalid baggage fields makes sense here - that will still let the program continue, but will inform the user that there probably is some invalid encoding in the baggage data.

}
BaggageEntryMetadata baggageEntryMetadata =
metadataValue != null
? BaggageEntryMetadata.create(metadataValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,40 @@ void extract_member_someInvalid() {
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}

@ParameterizedTest
@MethodSource
void extract_member_invalidPercentEncoding_preservesValidMembers(
String header, Baggage expectedBaggage) {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();

Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", header), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}

static Stream<Arguments> extract_member_invalidPercentEncoding_preservesValidMembers() {
return Stream.of(
Arguments.argumentSet(
"invalid entry at beginning",
"bad=va%lue,key1=value1,encoded=value%202",
Baggage.builder().put("key1", "value1").put("encoded", "value 2").build()),
Arguments.argumentSet(
"invalid entry in middle",
"key1=value1,bad=va%lue,encoded=value%202,key2=value2",
Baggage.builder()
.put("key1", "value1")
.put("encoded", "value 2")
.put("key2", "value2")
.build()),
Arguments.argumentSet(
"invalid entry at end",
"key1=value1,encoded=value%202,bad=va%lue",
Baggage.builder().put("key1", "value1").put("encoded", "value 2").build()),
Arguments.argumentSet(
"multiple invalid entries",
"bad1=va%lue,key1=value1,bad2=value%GG,encoded=value%202,bad3=value;meta=%GG",
Baggage.builder().put("key1", "value1").put("encoded", "value 2").build()));
}

@Test
void extract_nullContext() {
assertThat(W3CBaggagePropagator.getInstance().extract(null, Collections.emptyMap(), getter))
Expand Down
Loading