Skip to content

Commit

Permalink
Addressed feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
santileira committed Jul 4, 2024
1 parent 9864776 commit bff973d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion baggage/baggage.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,12 @@ func parsePropertyInternal(s string) (p Property, ok bool) {
}

// Decode a percent-encoded value.
value, err := url.PathUnescape(s[valueStart:valueEnd])
rawVal := s[valueStart:valueEnd]
unescapeVal, err := url.PathUnescape(rawVal)
if err != nil {
return
}
value := replaceInvalidUTF8Sequences(rawVal, unescapeVal)

ok = true
p.key = s[keyStart:keyEnd]
Expand Down
11 changes: 8 additions & 3 deletions baggage/baggage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,14 @@ func TestBaggageParse(t *testing.T) {
},
{
name: "percent-encoded octet sequences do not match the UTF-8 encoding scheme",
in: "k=aa%ffcc",
in: "k=aa%ffcc;p=d%fff",
want: baggage.List{
"k": {Value: "aa�cc"},
"k": {
Value: "aa�cc",
Properties: []baggage.Property{
{Key: "p", Value: "d�f", HasValue: true},
},
},
},
},
}
Expand Down Expand Up @@ -1034,7 +1039,7 @@ func BenchmarkParse(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
benchBaggage, _ = Parse("userId=alice,serverNode = DF28 , isProduction = false,hasProp=stuff;propKey;propWValue=value, propKeyUtf8=pr%ffo%ffp%fcValue")
benchBaggage, _ = Parse("userId=alice,serverNode = DF28 , isProduction = false,hasProp=stuff;propKey;propWValue=value, invalidUtf8=pr%ffo%ffp%fcValue")
}
}

Expand Down

0 comments on commit bff973d

Please sign in to comment.