-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fixes #3038 "v3 Flash Message with redirect is not working" #3046
Conversation
WalkthroughThe changes introduce a refactor and enhancement to the handling of flash messages in the Changes
Sequence DiagramsequenceDiagram
participant User
participant App
participant Redirect
User ->> App: Request to /any-route
App ->> Redirect: c.Redirect().processFlashMessages()
Redirect -->> User: Sets flash messages as cookies and redirects
Note over App, User: Flash messages stored and cleared on redirection
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3046 +/- ##
==========================================
+ Coverage 82.85% 82.90% +0.05%
==========================================
Files 115 115
Lines 8224 8226 +2
==========================================
+ Hits 6814 6820 +6
+ Misses 1080 1077 -3
+ Partials 330 329 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- redirect.go (4 hunks)
- redirect_test.go (11 hunks)
- router.go (1 hunks)
Additional comments not posted (6)
redirect.go (2)
185-186
: Ensure proper processing of flash messages.The new method
processFlashMessages
is correctly invoked after setting the status and before returning in theTo
method. This ensures that the flash messages are processed and set as cookies appropriately before the redirection response is sent.
243-244
: Review ofparseAndClearFlashMessages
andprocessFlashMessages
.
parseAndClearFlashMessages
:
- This method correctly parses the cookie value for flash messages and clears the flash cookie after parsing. It ensures that flash messages are only available for the current request cycle, enhancing security by preventing stale flash message retrieval.
- The use of
findNextNonEscapedCharsetPosition
for parsing is efficient and handles potential character escaping within the cookie values.
processFlashMessages
:
- Efficiently combines flash messages and old input data into a single cookie.
- The use of
bytebufferpool
for string manipulation is a good practice to avoid unnecessary memory allocations.- Correctly clears the
messages
andoldInput
after processing to prevent data leakage on subsequent requests.- The use of
SessionOnly
cookie attribute is a good security practice as it ensures that the cookie is not persisted across sessions.Overall, these methods are well-implemented with attention to performance, security, and correctness.
Also applies to: 262-296
router.go (1)
228-228
: Updated method call inrequestHandler
.The replacement of
setFlash
withparseAndClearFlashMessages
is correctly implemented. This change is consistent with the renaming inredirect.go
and ensures that the updated method is called to clear flash messages appropriately during request processing.redirect_test.go (3)
37-53
: Test coverage for redirection with flash messages.The new test
Test_Redirect_To_WithFlashMessages
correctly checks the functionality of setting flash messages during redirection and ensures that the messages are correctly set in the response cookies. The test also validates the clearing of flash messages, which is crucial for security and correctness.
170-191
: Test coverage forBack
redirection with flash messages.The test
Test_Redirect_Back_WithFlashMessages
effectively validates the behavior of theBack
method when flash messages are involved. It checks both the setting and clearing of flash messages, ensuring that the functionality aligns with the expected behavior after the recent changes.
Line range hint
264-277
: Validation ofparseAndClearFlashMessages
functionality.The test
Test_Redirect_parseAndClearFlashMessages
is crucial as it directly tests the new method introduced inredirect.go
. It ensures that the method correctly parses and clears the flash messages and old input data from the cookies, verifying both the retrieval of messages and inputs and their removal after processing.
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- redirect_test.go (12 hunks)
Files skipped from review as they are similar to previous changes (1)
- redirect_test.go
🐞 [Bug]: v3 Flash Message with redirect is not working #3038
fixes #3038