fix(web): escape file paths

This commit is contained in:
Masahiko AMANO 2023-01-29 00:43:44 +03:00
parent f5eb8dac06
commit b55865b8e7

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"net/url"
"os" "os"
"path" "path"
"strconv" "strconv"
@ -138,8 +139,13 @@ func HandlerTDBMS(w http.ResponseWriter, r *http.Request) {
return return
} }
for index, element := range json_response.Data { for index, element := range json_response.Data {
json_response.Data[index]["path"] = path := strings.ReplaceAll(element["path"].(string), "/srv/data/tfm/", "")
strings.ReplaceAll(element["path"].(string), "/srv/data/tfm/", "") splitpath := strings.Split(path, "/")
for pindex, pelement := range splitpath {
splitpath[pindex] = url.PathEscape(pelement)
}
path = strings.Join(splitpath, "/")
json_response.Data[index]["path"] = path
} }
response, err = json.Marshal(json_response) response, err = json.Marshal(json_response)
} }