Repository: gohugoio/hugo (language: go)

Issue:
Hugo server cannot find page when file path contains bytes > 0x80
With this structure...

```text
content/
├── post/
│   └── hügö.md
└── _index.md
```

...`hugo server` displays "Page Not Found" when visiting `http://localhost:1313/post/hügö/`. 

- This problem is limited to `hugo server`. The page is correctly rendered to public when running `hugo`.
- Problem was introduced in v0.103.0.
- Git bisect says a5cda5ca4dc9ced8179eb6bcccb1bbdc567afe17 is the first bad commit

Ref: <https://discourse.gohugo.io/t/40560/>

MRE:

```bash
git clone --single-branch -b hugo-github-issue-10287 https://github.com/jmooring/hugo-testing hugo-github-issue-10287
cd hugo-github-issue-10287
hugo server
```



Discussion / hints:
To be clear: This was introduced back when the server redirect feature was added, but obviously became more visible now that we add a default 404 redirect if not set.



Fix patch:
diff --git a/commands/server.go b/commands/server.go
index 7689f03dbc4..06b7612fcc5 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -400,13 +400,14 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, net.Listener, string
 			}
 
 			// Ignore any query params for the operations below.
-			requestURI := strings.TrimSuffix(r.RequestURI, "?"+r.URL.RawQuery)
+			requestURI, _ := url.PathUnescape(strings.TrimSuffix(r.RequestURI, "?"+r.URL.RawQuery))
 
 			for _, header := range f.c.serverConfig.MatchHeaders(requestURI) {
 				w.Header().Set(header.Key, header.Value)
 			}
 
 			if redirect := f.c.serverConfig.MatchRedirect(requestURI); !redirect.IsZero() {
+				// fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name)))
 				doRedirect := true
 				// This matches Netlify's behaviour and is needed for SPA behaviour.
 				// See https://docs.netlify.com/routing/redirects/rewrites-proxies/


Test patch:
diff --git a/commands/commands_test.go b/commands/commands_test.go
index d37ec1f0d6c..5b5e9aa81ed 100644
--- a/commands/commands_test.go
+++ b/commands/commands_test.go
@@ -47,7 +47,7 @@ func TestExecute(t *testing.T) {
 		c.Assert(resp.Err, qt.IsNil)
 		result := resp.Result
 		c.Assert(len(result.Sites) == 1, qt.Equals, true)
-		c.Assert(len(result.Sites[0].RegularPages()) == 1, qt.Equals, true)
+		c.Assert(len(result.Sites[0].RegularPages()) == 2, qt.Equals, true)
 		c.Assert(result.Sites[0].Info.Params()["myparam"], qt.Equals, "paramproduction")
 	})
 
@@ -362,11 +362,20 @@ weight: 1
 
 Content
 
+`)
+
+	writeFile(t, filepath.Join(dir, contentDir, "hügö.md"), `
+---
+weight: 2
+---
+
+This is hügö.
+
 `)
 
 	writeFile(t, filepath.Join(dir, "layouts", "_default", "single.html"), `
 
-Single: {{ .Title }}
+Single: {{ .Title }}|{{ .Content }}
 
 `)
 
diff --git a/commands/server_test.go b/commands/server_test.go
index 47cc8b9e9bf..a2fa1f37ad9 100644
--- a/commands/server_test.go
+++ b/commands/server_test.go
@@ -65,6 +65,19 @@ func TestServer404(t *testing.T) {
 	c.Assert(r.content404, qt.Contains, "404: 404 Page not found|Not Found.")
 }
 
+// Issue 10287.
+func TestServerUnicode(t *testing.T) {
+	c := qt.New(t)
+
+	r := runServerTest(c,
+		serverTestOptions{
+			pathsToGet: []string{"hügö/"},
+		},
+	)
+
+	c.Assert(r.err, qt.IsNil)
+	c.Assert(r.pathsResults["hügö/"], qt.Contains, "This is hügö")
+}
 func TestServerFlags(t *testing.T) {
 	c := qt.New(t)
 
@@ -125,6 +138,10 @@ func TestServerBugs(t *testing.T) {
 		numservers int
 		assert     func(c *qt.C, r serverTestResult)
 	}{
+		{"PostProcess, memory", "", "", 1, func(c *qt.C, r serverTestResult) {
+			c.Assert(r.err, qt.IsNil)
+			c.Assert(r.homesContent[0], qt.Contains, "PostProcess: /foo.min.css")
+		}},
 		// Issue 9788
 		{"PostProcess, memory", "", "", 1, func(c *qt.C, r serverTestResult) {
 			c.Assert(r.err, qt.IsNil)
@@ -187,17 +204,23 @@ type serverTestResult struct {
 	homesContent   []string
 	content404     string
 	publicDirnames map[string]bool
+	pathsResults   map[string]string
 }
 
 type serverTestOptions struct {
 	getNumHomes int
 	test404     bool
 	config      string
+	pathsToGet  []string
 	args        []string
 }
 
-func runServerTest(c *qt.C, opts serverTestOptions) (result serverTestResult) {
+func runServerTest(c *qt.C, opts serverTestOptions) serverTestResult {
 	dir := createSimpleTestSite(c, testSiteConfig{configTOML: opts.config})
+	result := serverTestResult{
+		publicDirnames: make(map[string]bool),
+		pathsResults:   make(map[string]string),
+	}
 
 	sp, err := helpers.FindAvailablePort()
 	c.Assert(err, qt.IsNil)
@@ -228,13 +251,17 @@ func runServerTest(c *qt.C, opts serverTestOptions) (result serverTestResult) {
 	if opts.getNumHomes > 0 {
 		// Esp. on slow CI machines, we need to wait a little before the web
 		// server is ready.
-		time.Sleep(567 * time.Millisecond)
+		wait := 567 * time.Millisecond
+		if os.Getenv("CI") != "" {
+			wait = 2 * time.Second
+		}
+		time.Sleep(wait)
 		result.homesContent = make([]string, opts.getNumHomes)
 		for i := 0; i < opts.getNumHomes; i++ {
 			func() {
 				resp, err := http.Get(fmt.Sprintf("http://localhost:%d/", port+i))
-				c.Check(err, qt.IsNil)
-				c.Check(resp.StatusCode, qt.Equals, http.StatusOK)
+				c.Assert(err, qt.IsNil)
+				c.Assert(resp.StatusCode, qt.Equals, http.StatusOK)
 				if err == nil {
 					defer resp.Body.Close()
 					result.homesContent[i] = helpers.ReaderToString(resp.Body)
@@ -243,10 +270,22 @@ func runServerTest(c *qt.C, opts serverTestOptions) (result serverTestResult) {
 		}
 	}
 
+	for _, path := range opts.pathsToGet {
+		func() {
+			resp, err := http.Get(fmt.Sprintf("http://localhost:%d/%s", port, path))
+			c.Assert(err, qt.IsNil)
+			c.Assert(resp.StatusCode, qt.Equals, http.StatusOK)
+			if err == nil {
+				defer resp.Body.Close()
+				result.pathsResults[path] = helpers.ReaderToString(resp.Body)
+			}
+		}()
+	}
+
 	if opts.test404 {
 		resp, err := http.Get(fmt.Sprintf("http://localhost:%d/this-page-does-not-exist", port))
-		c.Check(err, qt.IsNil)
-		c.Check(resp.StatusCode, qt.Equals, http.StatusNotFound)
+		c.Assert(err, qt.IsNil)
+		c.Assert(resp.StatusCode, qt.Equals, http.StatusNotFound)
 		if err == nil {
 			defer resp.Body.Close()
 			result.content404 = helpers.ReaderToString(resp.Body)
@@ -261,15 +300,14 @@ func runServerTest(c *qt.C, opts serverTestOptions) (result serverTestResult) {
 	}
 
 	pubFiles, err := os.ReadDir(filepath.Join(dir, "public"))
-	c.Check(err, qt.IsNil)
-	result.publicDirnames = make(map[string]bool)
+	c.Assert(err, qt.IsNil)
 	for _, f := range pubFiles {
 		result.publicDirnames[f.Name()] = true
 	}
 
 	result.err = wg.Wait()
 
-	return
+	return result
 
 }