Skip to content

Commit

Permalink
parsePropertyInternal sets p.hasValue only for a valid input
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Dec 8, 2023
1 parent ff7e331 commit fba4b9e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions baggage/baggage.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ func (b Baggage) String() string {

// parsePropertyInternal attempts to decode a Property from the passed string.
func parsePropertyInternal(s string) (p Property, ok bool) {
// Attempting to parse the key.
index := skipSpace(s, 0)

keyStart := index
Expand All @@ -545,27 +546,27 @@ func parsePropertyInternal(s string) (p Property, ok bool) {
}

if keyStart == keyEnd {
// Invalid key.
return
}

index = skipSpace(s, keyEnd)

p.key = s[keyStart:keyEnd]

// this matches only the key
if index == len(s) {
// There is only a key (no value).
ok = true
return
}

// now let see if it matches the key and the value

if s[index] != keyValueDelimiter[0] {
// Bad key-value delimiter.
return
}

Check warning on line 567 in baggage/baggage.go

View check run for this annotation

Codecov / codecov/patch

baggage/baggage.go#L565-L567

Added lines #L565 - L567 were not covered by tests

// we set it to true as soon as we find the delimiter even if it is empty
p.hasValue = true

// Attempting to parse the value.
index = skipSpace(s, index+1)

valueStart := index
Expand All @@ -579,11 +580,13 @@ func parsePropertyInternal(s string) (p Property, ok bool) {

index = skipSpace(s, valueEnd)
if index != len(s) {
// Invalid value.
return
}

// value can be empty, so no need to do the same check here
ok = true
// If there is a delimiter, we set hasValue to true even if the value is empty.
p.hasValue = true
p.value = s[valueStart:valueEnd]
return
}
Expand Down

0 comments on commit fba4b9e

Please sign in to comment.