Plugins: Compose filesystem paths with filepath.Join (#28375)

* plugins: Fix filesystem path composition

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* plugins: Use filepath.Join to join filesystem paths

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-10-19 17:35:31 +02:00
committed by GitHub
parent 762a7195a6
commit 89d10c706a
8 changed files with 16 additions and 17 deletions
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"github.com/grafana/grafana/pkg/models"
@@ -338,7 +337,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) Response {
filePath := hs.Cfg.DefaultHomeDashboardPath
if filePath == "" {
filePath = path.Join(hs.Cfg.StaticRootPath, "dashboards/home.json")
filePath = filepath.Join(hs.Cfg.StaticRootPath, "dashboards/home.json")
}
file, err := os.Open(filePath)
+2 -2
View File
@@ -4,7 +4,7 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"path"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
@@ -55,7 +55,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg) (*macaron.Macaron, *HT
m := macaron.New()
m.Use(middleware.GetContextHandler(nil, nil, nil))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
Directory: filepath.Join(setting.StaticRootPath, "views"),
IndentJSON: true,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"sync"
"github.com/grafana/grafana/pkg/services/live"
@@ -331,7 +332,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
}
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
Directory: filepath.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))