Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: static file routing path rewrite. #1538

Merged
merged 4 commits into from Oct 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions router.go
Expand Up @@ -327,8 +327,11 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Router {
if len(path) >= prefixLen {
if isStar && app.getString(path[0:prefixLen]) == prefix {
path = append(path[0:0], '/')
} else if len(path) > 0 && path[len(path)-1] != '/' {
path = append(path[prefixLen:], '/')
} else {
path = path[prefixLen:]
if len(path) == 0 || path[len(path)-1] != '/' {
path = append(path, '/')
}
Comment on lines +331 to +334
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a unit test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go test -v -run=^Test_Route_Static
=== RUN   Test_Route_Static_Root
--- PASS: Test_Route_Static_Root (0.01s)
=== RUN   Test_Route_Static_HasPrefix
--- PASS: Test_Route_Static_HasPrefix (0.00s)
PASS
ok      github.com/gofiber/fiber/v2     0.077s

}
}
if len(path) > 0 && path[0] != '/' {
Expand Down