fix: support legacy label arrays
This commit is contained in:
parent
539e046a22
commit
b1f4d7c318
@ -60,12 +60,25 @@ func labelNames(raw string) []string {
|
||||
var labels []struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(raw), &labels); err != nil {
|
||||
if err := json.Unmarshal([]byte(raw), &labels); err == nil {
|
||||
out := make([]string, 0, len(labels))
|
||||
for _, label := range labels {
|
||||
name := strings.TrimSpace(label.Name)
|
||||
if name != "" {
|
||||
out = append(out, name)
|
||||
}
|
||||
}
|
||||
if len(out) > 0 {
|
||||
return out
|
||||
}
|
||||
}
|
||||
var names []string
|
||||
if err := json.Unmarshal([]byte(raw), &names); err != nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]string, 0, len(labels))
|
||||
for _, label := range labels {
|
||||
name := strings.TrimSpace(label.Name)
|
||||
out := make([]string, 0, len(names))
|
||||
for _, name := range names {
|
||||
name = strings.TrimSpace(name)
|
||||
if name != "" {
|
||||
out = append(out, name)
|
||||
}
|
||||
|
||||
@ -35,3 +35,10 @@ func TestBuildToleratesBadLabelJSON(t *testing.T) {
|
||||
t.Fatalf("dedupe text: %q", doc.DedupeText)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildSupportsLegacyStringLabels(t *testing.T) {
|
||||
doc := Build(store.Thread{Title: "A", LabelsJSON: `["bug","help wanted"]`})
|
||||
if doc.DedupeText != "a bug help wanted" {
|
||||
t.Fatalf("dedupe text: %q", doc.DedupeText)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user