Skip to content

Commit bae1e2f

Browse files
committed
Fix for validating tags in dashboard json in backend, Fixes grafana#2152
1 parent 7ce31bf commit bae1e2f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/models/dashboards.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewDashboard(title string) *Dashboard {
4949
// GetTags turns the tags in data json into go string array
5050
func (dash *Dashboard) GetTags() []string {
5151
jsonTags := dash.Data["tags"]
52-
if jsonTags == nil {
52+
if jsonTags == nil || jsonTags == "" {
5353
return []string{}
5454
}
5555

pkg/models/dashboard_test.go pkg/models/dashboards_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,17 @@ func TestDashboardModel(t *testing.T) {
1515
So(dashboard.Slug, ShouldEqual, "grafana-play-home")
1616
})
1717

18+
Convey("Given a dashboard json", t, func() {
19+
json := map[string]interface{}{
20+
"title": "test dash",
21+
}
22+
23+
Convey("With tags as string value", func() {
24+
json["tags"] = ""
25+
dash := NewDashboardFromJson(json)
26+
27+
So(len(dash.GetTags()), ShouldEqual, 0)
28+
})
29+
})
30+
1831
}

0 commit comments

Comments
 (0)