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

fixes #3038 "v3 Flash Message with redirect is not working" #3046

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

ReneWerner87
Copy link
Member

🐞 [Bug]: v3 Flash Message with redirect is not working #3038

fixes #3038

🐞 [Bug]: v3 Flash Message with redirect is not working #3038
@ReneWerner87 ReneWerner87 added this to the v3 milestone Jun 27, 2024
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner June 27, 2024 12:11
@ReneWerner87 ReneWerner87 requested review from gaby, sixcolors and efectn and removed request for a team June 27, 2024 12:11
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The changes introduce a refactor and enhancement to the handling of flash messages in the Redirect struct of the Go project. The processFlashMessages method centralizes the logic for flash messages and clears them after use. Updates to the methods and tests ensure consistency and correctness in redirect operations involving flash messages.

Changes

File Change Summary
redirect.go Added processFlashMessages and modified setFlash to parseAndClearFlashMessages for cleaner code separation.
redirect_test.go Added new tests: Test_Redirect_To_WithFlashMessages, Test_Redirect_Back_WithFlashMessages, and Test_Redirect_parseAndClearFlashMessages to ensure flash message handling works correctly.
router.go Updated the requestHandler method to use parseAndClearFlashMessages instead of setFlash.

Sequence Diagram

sequenceDiagram
    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
Loading

Assessment against linked issues

Objective (Issue No) Addressed Explanation
Flash message not working with redirect (#3038)

Poem

In the world of code so bright and clear,
Redirects now bring messages near.
Flash messages stored with care,
In each redirect, they're always there.
Tests ensure the code's delight,
🌟 With every fix, it's shining bright. 🌟


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.90%. Comparing base (c9b7b1a) to head (a8e36ee).

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     
Flag Coverage Δ
unittests 82.90% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between c9b7b1a and a29d65e.

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 the To method. This ensures that the flash messages are processed and set as cookies appropriately before the redirection response is sent.


243-244: Review of parseAndClearFlashMessages and processFlashMessages.

  1. 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.
  2. 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 and oldInput 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 in requestHandler.

The replacement of setFlash with parseAndClearFlashMessages is correctly implemented. This change is consistent with the renaming in redirect.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 for Back redirection with flash messages.

The test Test_Redirect_Back_WithFlashMessages effectively validates the behavior of the Back 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 of parseAndClearFlashMessages functionality.

The test Test_Redirect_parseAndClearFlashMessages is crucial as it directly tests the new method introduced in redirect.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.

🐞 [Bug]: v3 Flash Message with redirect is not working #3038
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between a29d65e and a8e36ee.

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

@ReneWerner87 ReneWerner87 merged commit dbba6cf into main Jun 28, 2024
15 checks passed
@efectn efectn deleted the Flash-Message-with-redirect branch September 1, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

🐞 [Bug]: v3 Flash Message with redirect is not working
3 participants