Home / File/ static.go — fiber Source File

static.go — fiber Source File

Architecture documentation for static.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberCore Adapters 1 imports 3 functions 7 classes

Entity Profile

Dependency Diagram

graph LR
  3c44fb0a_14a9_26fb_2c78_c413f4b9d39d["static.go"]
  c0b86961_3ef1_0168_52fc_98627566ed27["bytes"]
  3c44fb0a_14a9_26fb_2c78_c413f4b9d39d --> c0b86961_3ef1_0168_52fc_98627566ed27
  style 3c44fb0a_14a9_26fb_2c78_c413f4b9d39d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package static

import (
	"bytes"
	"errors"
	"fmt"
	"io/fs"
	"net/url"
	"os"
	pathpkg "path"
	"path/filepath"
	"slices"
	"strconv"
	"strings"
	"sync"

	"github.com/gofiber/utils/v2"
	"github.com/valyala/fasthttp"

	"github.com/gofiber/fiber/v3"
)

var ErrInvalidPath = errors.New("invalid path")

// sanitizePath validates and cleans the requested path.
// It returns an error if the path attempts to traverse directories.
func sanitizePath(p []byte, filesystem fs.FS) ([]byte, error) {
	var s string

	hasTrailingSlash := len(p) > 0 && p[len(p)-1] == '/'

	if bytes.IndexByte(p, '\\') >= 0 {
		b := make([]byte, len(p))
		copy(b, p)
		for i := range b {
			if b[i] == '\\' {
				b[i] = '/'
			}
		}
		s = utils.UnsafeString(b)
	} else {
		s = utils.UnsafeString(p)
	}

	// repeatedly unescape until it no longer changes, catching errors
	for strings.IndexByte(s, '%') >= 0 {
		us, err := url.PathUnescape(s)
		if err != nil {
			return nil, ErrInvalidPath
		}
		if us == s {
			break
		}
		s = us
	}

	if strings.IndexByte(s, '\\') >= 0 {
		return nil, ErrInvalidPath
	}

// ... (239 more lines)

Domain

Subdomains

Dependencies

  • bytes

Frequently Asked Questions

What does static.go do?
static.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in static.go?
static.go defines 3 function(s): New, isFile, sanitizePath.
What does static.go depend on?
static.go imports 1 module(s): bytes.
Where is static.go in the architecture?
static.go is located at middleware/static/static.go (domain: FiberCore, subdomain: Adapters, directory: middleware/static).

Analyze Your Own Codebase

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

Try Supermodel Free