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: file opening path and directory browsing path of filesystem #1547

Merged
merged 2 commits into from Sep 29, 2021

Conversation

fufuok
Copy link
Contributor

@fufuok fufuok commented Sep 28, 2021

Please provide enough information so that others can review your pull request:

Fixes: #1546

github.com/fufuok/fiber/middleware/filesystem# go test -v
=== RUN   Test_FileSystem
=== RUN   Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type
=== RUN   Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#01
=== RUN   Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#02
=== RUN   Test_FileSystem/Should_be_returns_status_404
=== RUN   Test_FileSystem/Should_be_returns_status_404#01
=== RUN   Test_FileSystem/Should_be_returns_status_200
=== RUN   Test_FileSystem/Should_be_returns_status_403
=== RUN   Test_FileSystem/Should_list_the_directory_contents
=== RUN   Test_FileSystem/Should_list_the_directory_contents#01
=== RUN   Test_FileSystem/Should_be_returns_status_200#01
=== RUN   Test_FileSystem/Should_be_return_status_200
=== RUN   Test_FileSystem/PathPrefix_should_be_applied
--- PASS: Test_FileSystem (0.01s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#02 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_404 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_404#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_403 (0.00s)
    --- PASS: Test_FileSystem/Should_list_the_directory_contents (0.00s)
    --- PASS: Test_FileSystem/Should_list_the_directory_contents#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_return_status_200 (0.00s)
    --- PASS: Test_FileSystem/PathPrefix_should_be_applied (0.00s)
=== RUN   Test_FileSystem_Next
--- PASS: Test_FileSystem_Next (0.00s)
=== RUN   Test_FileSystem_NonGetAndHead
--- PASS: Test_FileSystem_NonGetAndHead (0.00s)
=== RUN   Test_FileSystem_Head
--- PASS: Test_FileSystem_Head (0.00s)
=== RUN   Test_FileSystem_NoRoot
--- PASS: Test_FileSystem_NoRoot (0.00s)
=== RUN   Test_FileSystem_UsingParam
--- PASS: Test_FileSystem_UsingParam (0.00s)
=== RUN   Test_FileSystem_UsingParam_NonFile
--- PASS: Test_FileSystem_UsingParam_NonFile (0.00s)
PASS
ok      github.com/gofiber/fiber/v2/middleware/filesystem       0.065s

@ReneWerner87
Copy link
Member

ReneWerner87 commented Sep 29, 2021

@fufuok can you use https://github.com/gofiber/fiber/blob/master/utils/strings.go#L56 instead of strings.TrimSuffix

image

@fufuok
Copy link
Contributor Author

fufuok commented Sep 29, 2021

@ReneWerner87
https://github.com/gofiber/fiber/blob/master/middleware/filesystem/filesystem.go#L152

Sure.
I see that strings.TrimSuffix is used in the existing code, in order to maintain consistency with it.
Change all to utils.TrimRight?

@ReneWerner87
Copy link
Member

Jo right

@ReneWerner87
Copy link
Member

Just use slash as a byte char with single quotes for the second parameter

@fufuok
Copy link
Contributor Author

fufuok commented Sep 29, 2021

github.com/fufuok/fiber/middleware/filesystem# go test -v
=== RUN   Test_FileSystem
=== RUN   Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type
=== RUN   Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#01
=== RUN   Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#02
=== RUN   Test_FileSystem/Should_be_returns_status_404
=== RUN   Test_FileSystem/Should_be_returns_status_404#01
=== RUN   Test_FileSystem/Should_be_returns_status_200
=== RUN   Test_FileSystem/Should_be_returns_status_403
=== RUN   Test_FileSystem/Should_list_the_directory_contents
=== RUN   Test_FileSystem/Should_list_the_directory_contents#01
=== RUN   Test_FileSystem/Should_be_returns_status_200#01
=== RUN   Test_FileSystem/Should_be_return_status_200
=== RUN   Test_FileSystem/PathPrefix_should_be_applied
--- PASS: Test_FileSystem (0.01s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200_with_suitable_content-type#02 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_404 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_404#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_403 (0.00s)
    --- PASS: Test_FileSystem/Should_list_the_directory_contents (0.00s)
    --- PASS: Test_FileSystem/Should_list_the_directory_contents#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_returns_status_200#01 (0.00s)
    --- PASS: Test_FileSystem/Should_be_return_status_200 (0.00s)
    --- PASS: Test_FileSystem/PathPrefix_should_be_applied (0.00s)
=== RUN   Test_FileSystem_Next
--- PASS: Test_FileSystem_Next (0.00s)
=== RUN   Test_FileSystem_NonGetAndHead
--- PASS: Test_FileSystem_NonGetAndHead (0.00s)
=== RUN   Test_FileSystem_Head
--- PASS: Test_FileSystem_Head (0.00s)
=== RUN   Test_FileSystem_NoRoot
--- PASS: Test_FileSystem_NoRoot (0.00s)
=== RUN   Test_FileSystem_UsingParam
--- PASS: Test_FileSystem_UsingParam (0.00s)
=== RUN   Test_FileSystem_UsingParam_NonFile
--- PASS: Test_FileSystem_UsingParam_NonFile (0.00s)
PASS
ok      github.com/gofiber/fiber/v2/middleware/filesystem       0.059s

Done.
Pass the test again. Please review it.

@ReneWerner87 ReneWerner87 merged commit 8b3a06b into gofiber:master Sep 29, 2021
@welcome
Copy link

welcome bot commented Sep 29, 2021

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Questions and fixes about filesystem middleware 🐛 Can't find index.html with PathPrefix?
3 participants