shithub: hugo

Download patch

ref: c4fa2f07996c7f1f4e257089a3c3c5b4c1339722
parent: 108314444b510bfc330ccac745dce7beccd52c91
author: Sam Smith <sams96@mail.com>
date: Sat Mar 7 13:56:02 EST 2020

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

--- a/tpl/data/data_test.go
+++ b/tpl/data/data_test.go
@@ -157,6 +157,11 @@
 			"",
 			false,
 		},
+		{
+			`pass/üńīçøðê-url.json`,
+			`{"gomeetup":["Sydney","San Francisco","Stockholm"]}`,
+			map[string]interface{}{"gomeetup": []interface{}{"Sydney", "San Francisco", "Stockholm"}},
+		},
 	} {
 
 		msg := qt.Commentf("Test %d", i)
--- a/tpl/data/resources.go
+++ b/tpl/data/resources.go
@@ -16,6 +16,7 @@
 import (
 	"io/ioutil"
 	"net/http"
+	"net/url"
 	"path/filepath"
 	"time"
 
@@ -107,7 +108,11 @@
 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
 		}