Skip to content

Commit ba39ad4

Browse files
committed
fix filename Git can not create under Windows
1 parent f6f4af7 commit ba39ad4

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

_fixture/dist/%2f..

Lines changed: 0 additions & 1 deletion
This file was deleted.

echo_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"runtime"
2121
"strings"
2222
"testing"
23+
"testing/fstest"
2324
"time"
2425

2526
"github.com/stretchr/testify/assert"
@@ -133,6 +134,11 @@ func TestNewDefaultFS(t *testing.T) {
133134
}
134135

135136
func TestEcho_StaticFS(t *testing.T) {
137+
dotsInFilenameFS := fstest.MapFS{
138+
// On Windows filename `%2f..` can not be created but in Linux it is possible.
139+
"%2f..": {Data: []byte("This filename is escaped to `/..` in URL.Path")},
140+
}
141+
136142
var testCases = []struct {
137143
givenFs fs.FS
138144
name string
@@ -280,12 +286,12 @@ func TestEcho_StaticFS(t *testing.T) {
280286
{
281287
name: "possible open redirect vulnerability when not unescaping path variables in static handler",
282288
givenPrefix: "/",
283-
givenFs: os.DirFS("_fixture/dist/"),
289+
givenFs: dotsInFilenameFS,
284290
givenEnablePathUnescapingStaticFiles: false,
285291
whenURL: "/%2f..",
286292
expectStatus: http.StatusOK,
287293
expectHeaderLocation: "",
288-
expectBodyStartsWith: "This filename is escaped to `/..` in URL.Path\n",
294+
expectBodyStartsWith: "This filename is escaped to `/..` in URL.Path",
289295
},
290296
}
291297

0 commit comments

Comments
 (0)