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 @@ -31,6 +31,8 @@ class Element {
}

private final BitSet excluded;
private final boolean allowEmpty;
private boolean seenWhitespace;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think we want to get rid of this, as right now we are accepting key1= but dropping key1= . The spec says:

Leading and trailing whitespaces (OWS) are allowed and are not considered to be a part of the value.

So i think this test needs to no longer return empty()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is still not addressed. You can remove this entire seenWhitespace variable and related code branches, and then the extract_value_onlySpaces test needs to be updated to:

  @Test
  void extract_value_onlySpaces() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();

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


private boolean leadingSpace;
private boolean readingValue;
Expand All @@ -40,20 +42,21 @@ class Element {
@Nullable private String value;

static Element createKeyElement() {
return new Element(EXCLUDED_KEY_CHARS);
return new Element(EXCLUDED_KEY_CHARS, /* allowEmpty= */ false);
}

static Element createValueElement() {
return new Element(EXCLUDED_VALUE_CHARS);
return new Element(EXCLUDED_VALUE_CHARS, /* allowEmpty= */ true);
}

/**
* Constructs element instance.
*
* @param excluded characters that are not allowed for this type of an element
*/
private Element(BitSet excluded) {
private Element(BitSet excluded, boolean allowEmpty) {
this.excluded = excluded;
this.allowEmpty = allowEmpty;
reset(0);
}

Expand All @@ -68,6 +71,7 @@ void reset(int start) {
readingValue = false;
trailingSpace = false;
value = null;
seenWhitespace = false;
}

boolean tryTerminating(int index, String header) {
Expand All @@ -77,6 +81,9 @@ boolean tryTerminating(int index, String header) {
if (this.trailingSpace) {
setValue(header);
return true;
} else if (allowEmpty && !seenWhitespace) {
this.value = "";
return true;
} else {
// leading spaces - no content, invalid
return false;
Expand Down Expand Up @@ -110,6 +117,8 @@ private static boolean isWhitespace(char character) {
private boolean tryNextWhitespace(int index) {
if (readingValue) {
markEnd(index);
} else {
seenWhitespace = true;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ void extract_value_empty() {
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key1="), getter);

assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
Baggage expectedBaggage = Baggage.builder().put("key1", "").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}

@Test
Expand All @@ -219,7 +220,9 @@ void extract_value_empty_withMetadata() {
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key1=;metakey=metaval"), getter);

assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
Baggage expectedBaggage =
Baggage.builder().put("key1", "", BaggageEntryMetadata.create("metakey=metaval")).build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}

@Test
Expand Down
Loading