Skip to content

Commit

Permalink
ddtrace/tracer: fix a bug with the x-datadog-tags header parser (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbayar committed Feb 9, 2022
1 parent 0de36b1 commit 4bb4d45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ddtrace/tracer/util.go
Expand Up @@ -102,11 +102,13 @@ func parsePropagatableTraceTags(s string) (map[string]string, error) {
for i, ch := range s {
switch ch {
case '=':
if !searchingKey || i-start == 0 {
return nil, fmt.Errorf("invalid format")
if searchingKey {
if i-start == 0 {
return nil, fmt.Errorf("invalid format")
}
key = s[start:i]
searchingKey, start = false, i+1
}
key = s[start:i]
searchingKey, start = false, i+1
case ',':
if searchingKey || i-start == 0 {
return nil, fmt.Errorf("invalid format")
Expand Down
2 changes: 2 additions & 0 deletions ddtrace/tracer/util_test.go
Expand Up @@ -100,10 +100,12 @@ func TestParsePropagatableTraceTags(t *testing.T) {
{"hello=world", map[string]string{"hello": "world"}, nil},
{" hello = world ", map[string]string{" hello ": " world "}, nil},
{"hello=world,service=account", map[string]string{"hello": "world", "service": "account"}, nil},
{"hello=wor=ld====,service=account,tag1=val=ue1", map[string]string{"hello": "wor=ld====", "service": "account", "tag1": "val=ue1"}, nil},
{"hello", nil, fmt.Errorf("invalid format")},
{"hello=world,service=", nil, fmt.Errorf("invalid format")},
{"hello=world,", nil, fmt.Errorf("invalid format")},
{"=world", nil, fmt.Errorf("invalid format")},
{"hello=,tag1=value1", nil, fmt.Errorf("invalid format")},
{",hello=world", nil, fmt.Errorf("invalid format")},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
Expand Down

0 comments on commit 4bb4d45

Please sign in to comment.