Home / Function/ Test_SanitizePath() — fiber Function Reference

Test_SanitizePath() — fiber Function Reference

Architecture documentation for the Test_SanitizePath() function in static_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  c318873a_4fad_172f_ae87_e86db21b94bf["Test_SanitizePath()"]
  f26a2d79_1e01_f027_82eb_45c4308747e8["static_test.go"]
  c318873a_4fad_172f_ae87_e86db21b94bf -->|defined in| f26a2d79_1e01_f027_82eb_45c4308747e8
  style c318873a_4fad_172f_ae87_e86db21b94bf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/static/static_test.go lines 1154–1195

func Test_SanitizePath(t *testing.T) {
	t.Parallel()

	type testCase struct {
		filesystem fs.FS
		name       string
		expectPath string
		input      []byte
	}

	testCases := []testCase{
		{name: "simple path", input: []byte("/foo/bar.txt"), expectPath: "/foo/bar.txt"},
		{name: "traversal attempt", input: []byte("/foo/../../bar.txt"), expectPath: "/bar.txt"},
		{name: "encoded traversal", input: []byte("/foo/%2e%2e/bar.txt"), expectPath: "/bar.txt"},
		{name: "double encoded traversal", input: []byte("/%252e%252e/bar.txt"), expectPath: "/bar.txt"},
		{name: "current dir reference", input: []byte("/foo/./bar.txt"), expectPath: "/foo/bar.txt"},
		{name: "encoded slash", input: []byte("/foo%2Fbar.txt"), expectPath: "/foo/bar.txt"},
		{name: "empty path", input: []byte(""), expectPath: "/"},
		{name: "dot segments", input: []byte("/foo/./bar/../baz.txt"), expectPath: "/foo/baz.txt"},
		{name: "leading dot segment", input: []byte("/./foo/bar.txt"), expectPath: "/foo/bar.txt"},
		{name: "encoded space", input: []byte("/foo%20bar/baz.txt"), expectPath: "/foo bar/baz.txt"},
		{name: "encoded plus literal", input: []byte("/foo+bar/baz.txt"), expectPath: "/foo+bar/baz.txt"},
		// windows-specific paths
		{name: "backslash path", input: []byte("\\foo\\bar.txt"), expectPath: "/foo/bar.txt"},
		{name: "backslash traversal", input: []byte("\\foo\\..\\..\\bar.txt"), expectPath: "/bar.txt"},
		{name: "mixed slashes", input: []byte("/foo\\bar.txt"), expectPath: "/foo/bar.txt"},
		{name: "trailing slash preserved", input: []byte("/foo/bar/"), expectPath: "/foo/bar/"},
		{name: "encoded trailing slash", input: []byte("/foo/bar%2F"), expectPath: "/foo/bar"},
		{filesystem: os.DirFS("."), name: "filesystem empty path", input: []byte(""), expectPath: "/"},
		{filesystem: os.DirFS("."), name: "filesystem trailing slash", input: []byte("/foo/"), expectPath: "/foo/"},
		{filesystem: os.DirFS("."), name: "filesystem traversal clean", input: []byte("/foo/../bar.txt"), expectPath: "/bar.txt"},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()
			got, err := sanitizePath(tc.input, tc.filesystem)
			require.NoError(t, err)
			require.Equal(t, tc.expectPath, string(got))
		})
	}
}

Domain

Subdomains

Frequently Asked Questions

What does Test_SanitizePath() do?
Test_SanitizePath() is a function in the fiber codebase, defined in middleware/static/static_test.go.
Where is Test_SanitizePath() defined?
Test_SanitizePath() is defined in middleware/static/static_test.go at line 1154.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free