Browse Source

Fix for validating tags in dashboard json in backend, Fixes #2152

Torkel Ödegaard 10 years ago
parent
commit
bae1e2f0c1
2 changed files with 14 additions and 1 deletions
  1. 1 1
      pkg/models/dashboards.go
  2. 13 0
      pkg/models/dashboards_test.go

+ 1 - 1
pkg/models/dashboards.go

@@ -49,7 +49,7 @@ func NewDashboard(title string) *Dashboard {
 // GetTags turns the tags in data json into go string array
 func (dash *Dashboard) GetTags() []string {
 	jsonTags := dash.Data["tags"]
-	if jsonTags == nil {
+	if jsonTags == nil || jsonTags == "" {
 		return []string{}
 	}
 

+ 13 - 0
pkg/models/dashboard_test.go → pkg/models/dashboards_test.go

@@ -15,4 +15,17 @@ func TestDashboardModel(t *testing.T) {
 		So(dashboard.Slug, ShouldEqual, "grafana-play-home")
 	})
 
+	Convey("Given a dashboard json", t, func() {
+		json := map[string]interface{}{
+			"title": "test dash",
+		}
+
+		Convey("With tags as string value", func() {
+			json["tags"] = ""
+			dash := NewDashboardFromJson(json)
+
+			So(len(dash.GetTags()), ShouldEqual, 0)
+		})
+	})
+
 }