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
Conversation
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
path = path[prefixLen:] | ||
if len(path) == 0 || path[len(path)-1] != '/' { | ||
path = append(path, '/') | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congrats, you made a good job.
@fufuok please correct the imports |
Done. ioutil.TempFile instead of os.CreateTemp Tested in go1.14 and go1.17.
|
@fufuok please check the existing tests should actually still work as they were without error |
https://github.com/gofiber/fiber/blob/master/app_test.go#L738 Please view this question gif and code: #1537 |
I think you are right, you can change the expectations |
Sorry, I rechecked the test case, because there is the default index.html in the directory, so it should be 200. I want to add another directory test case without index.html. Unlike #1537 , it has option If possible, I would like to submit the above code, please approve it. |
Please provide enough information so that others can review your pull request:
Fixes: #1537