tpl: Fix error with unicode in file paths
authorSam Smith <sams96@mail.com>
Sat, 7 Mar 2020 18:56:02 +0000 (18:56 +0000)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 9 Mar 2020 12:31:04 +0000 (13:31 +0100)
Add url.QueryUnescape before reading file which allows files with
unicode in their paths to be read.

Fixes #6996

tpl/data/data_test.go
tpl/data/resources.go

index 8bd4edc98e05bf4783aa46e7c0c19292fc01e73a..fa99006b24fc1fff481af0caa25f26a0f27f814d 100644 (file)
@@ -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)
index 7de440ca65fbb6c717661de9b2a57098bb98afb8..923d5946e0e6cf89f8a7ff586ca7a60f934cc210 100644 (file)
@@ -16,6 +16,7 @@ package data
 import (
        "io/ioutil"
        "net/http"
+       "net/url"
        "path/filepath"
        "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 {
        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
                }