Skip to content

Commit

Permalink
runtime: pprof label need to escape double quote
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweixie committed Jul 7, 2022
1 parent 351e0f4 commit 2cc08d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/runtime/pprof/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func Labels(args ...string) LabelSet {
}
list := make([]label, 0, len(args)/2)
for i := 0; i+1 < len(args); i += 2 {
list = append(list, label{key: args[i], value: args[i+1]})
key := strings.ReplaceAll(args[i], `"`, `\"`)
value := strings.ReplaceAll(args[i+1], `"`, `\"`)
list = append(list, label{key: key, value: value})
}
return LabelSet{list: list}
}
Expand Down
15 changes: 15 additions & 0 deletions src/runtime/pprof/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"reflect"
"sort"
"strings"
"testing"
)

Expand Down Expand Up @@ -81,6 +82,20 @@ func TestContextLabels(t *testing.T) {
}
}

func TestQuoteLabels(t *testing.T) {
key := `a "quote" key`
value := `a "quote" value`
quoteKey := strings.ReplaceAll(key, `"`, `\"`)
quoteValue := strings.ReplaceAll(value, `"`, `\"`)
l := Labels(key, value)
if l.list[0].key != quoteKey {
t.Errorf("labels: got %s, want %s", l.list[0].key, quoteKey)
}
if l.list[0].value != quoteValue {
t.Errorf("labels: got %s, want %s", l.list[0].value, quoteValue)
}
}

func TestLabelMapStringer(t *testing.T) {
for _, tbl := range []struct {
m labelMap
Expand Down

0 comments on commit 2cc08d5

Please sign in to comment.