Skip to content

Commit

Permalink
tpl: Fix error with unicode in file paths
Browse files Browse the repository at this point in the history
Add url.QueryUnescape before reading file which allows files with
unicode in their paths to be read.

Fixes #6996
  • Loading branch information
sams96 authored and bep committed Mar 9, 2020
1 parent 1083144 commit c4fa2f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tpl/data/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ func TestGetJSON(t *testing.T) {
"",
false,
},
{
`pass/üńīçøðê-url.json`,
`{"gomeetup":["Sydney","San Francisco","Stockholm"]}`,
map[string]interface{}{"gomeetup": []interface{}{"Sydney", "San Francisco", "Stockholm"}},
},
} {

msg := qt.Commentf("Test %d", i)
Expand Down
7 changes: 6 additions & 1 deletion tpl/data/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package data
import (
"io/ioutil"
"net/http"
"net/url"
"path/filepath"
"time"

Expand Down Expand Up @@ -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 {
switch req.URL.Scheme {
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 {
return err
}
Expand Down

0 comments on commit c4fa2f0

Please sign in to comment.