tpl: Fix error with unicode in file paths

Add url.QueryUnescape before reading file which allows files with
unicode in their paths to be read.

Fixes #6996
This commit is contained in:
Sam Smith 2020-03-07 18:56:02 +00:00 committed by Bjørn Erik Pedersen
parent 108314444b
commit c4fa2f0799
2 changed files with 11 additions and 1 deletions

View file

@ -157,6 +157,11 @@ func TestGetJSON(t *testing.T) {
"", "",
false, false,
}, },
{
`pass/üńīçøðê-url.json`,
`{"gomeetup":["Sydney","San Francisco","Stockholm"]}`,
map[string]interface{}{"gomeetup": []interface{}{"Sydney", "San Francisco", "Stockholm"}},
},
} { } {
msg := qt.Commentf("Test %d", i) msg := qt.Commentf("Test %d", i)

View file

@ -16,6 +16,7 @@ package data
import ( import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url"
"path/filepath" "path/filepath"
"time" "time"
@ -107,7 +108,11 @@ func getLocal(url string, fs afero.Fs, cfg config.Provider) ([]byte, error) {
func (ns *Namespace) getResource(cache *filecache.Cache, unmarshal func(b []byte) (bool, error), req *http.Request) error { func (ns *Namespace) getResource(cache *filecache.Cache, unmarshal func(b []byte) (bool, error), req *http.Request) error {
switch req.URL.Scheme { switch req.URL.Scheme {
case "": case "":
b, err := getLocal(req.URL.String(), ns.deps.Fs.Source, ns.deps.Cfg) url, err := url.QueryUnescape(req.URL.String())
if err != nil {
return err
}
b, err := getLocal(url, ns.deps.Fs.Source, ns.deps.Cfg)
if err != nil { if err != nil {
return err return err
} }