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 (v3): handle un-matched open brackets in the query params #3126

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

dojutsu-user
Copy link
Contributor

Description

Add logic to keep count of open brackets. If there's a mismatch between the number of open and close brackets, then return error.

Fixes #3120

Type of change

Please delete options that are not relevant.

  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

Commit formatting

Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md

@dojutsu-user dojutsu-user requested a review from a team as a code owner September 7, 2024 11:27
@dojutsu-user dojutsu-user requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team September 7, 2024 11:27
Copy link
Contributor

coderabbitai bot commented Sep 7, 2024

Walkthrough

The changes enhance error handling in the parseParamSquareBrackets function by implementing a mechanism to track unmatched square brackets in input strings. The new logic counts opening and closing brackets, returning errors for unmatched cases. Additionally, a new test function validates this behavior, ensuring robust error handling for various scenarios involving bracketed input.

Changes

Files Change Summary
binder/mapping.go Enhanced error handling in parseParamSquareBrackets for unmatched brackets.
binder/mapping_test.go Added Test_ParseParamSquareBrackets to validate parsing behavior, including error cases.

Assessment against linked issues

Objective Addressed Explanation
Prevent panic on specific query param (#3120)
Ensure proper error handling for unmatched brackets (#3120)

Poem

In the meadow, I hop with glee,
No more panic, just harmony!
Brackets now dance in perfect pairs,
Parsing with joy, free from cares.
A rabbit's cheer for code so bright,
Error-free days, oh what a delight! 🐇✨


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 Sep 7, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.18%. Comparing base (f668537) to head (3b43e4f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
binder/mapping.go 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3126      +/-   ##
==========================================
+ Coverage   80.06%   80.18%   +0.11%     
==========================================
  Files         117      117              
  Lines        9038     9047       +9     
==========================================
+ Hits         7236     7254      +18     
+ Misses       1371     1360      -11     
- Partials      431      433       +2     
Flag Coverage Δ
unittests 80.18% <84.61%> (+0.11%) ⬆️

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: 1

Outside diff range, codebase verification and nitpick comments (1)
binder/mapping.go (1)

Line range hint 137-166: Robust implementation with a minor suggestion for improvement.

The modifications to the parseParamSquareBrackets function enhance its robustness by effectively handling unmatched brackets. The logic for counting and validating brackets is well-implemented.

Suggestion:
To further improve readability, consider extracting the bracket counting and validation logic into a separate function. This would make the parseParamSquareBrackets function cleaner and easier to maintain.

Tools
GitHub Check: codecov/patch

[warning] 144-144: binder/mapping.go#L144
Added line #L144 was not covered by tests

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f668537 and 22b9490.

Files selected for processing (2)
  • binder/mapping.go (3 hunks)
  • binder/mapping_test.go (2 hunks)
Additional context used
golangci-lint
binder/mapping_test.go

35-35: fieldalignment: struct with 48 pointer bytes could be 40

(govet)

GitHub Check: lint
binder/mapping_test.go

[failure] 35-35:
fieldalignment: struct with 48 pointer bytes could be 40 (govet)

GitHub Check: codecov/patch
binder/mapping.go

[warning] 144-144: binder/mapping.go#L144
Added line #L144 was not covered by tests

binder/mapping_test.go Outdated Show resolved Hide resolved
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 22b9490 and 40f3505.

Files selected for processing (1)
  • binder/mapping_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • binder/mapping_test.go

@gaby
Copy link
Member

gaby commented Sep 8, 2024

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Sep 8, 2024

Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Sep 8, 2024

Walkthrough

The changes introduced in the pull request enhance the error handling of the parseParamSquareBrackets function within the binder/mapping.go file. A new variable tracks the count of open square brackets, allowing for improved validation of bracket matching. Corresponding tests have been added to the binder/mapping_test.go file to cover various scenarios, including both correctly formatted inputs and cases with unmatched brackets. This ensures that the function can handle parsing errors more effectively.

Changes

Files Change Summary
binder/mapping.go Improved error handling in parseParamSquareBrackets for unmatched brackets.
binder/mapping_test.go Added Test_ParseParamSquareBrackets to validate parsing logic with various test cases.

Assessment against linked issues

Objective Addressed Explanation
Panic on specific query param for QueryParser (#3120)

Poem

In the land of code, a rabbit did hop,
Fixing brackets, it never would stop.
With tests all around, errors now flee,
Parsing so smooth, as happy as can be!
Hooray for the changes, let’s give a cheer,
For a world without panic, let’s spread the cheer! 🐇✨


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f668537 and 40f3505.

Files selected for processing (2)
  • binder/mapping.go (3 hunks)
  • binder/mapping_test.go (2 hunks)
Additional context used
GitHub Check: codecov/patch
binder/mapping.go

[warning] 144-144: binder/mapping.go#L144
Added line #L144 was not covered by tests

Additional comments not posted (1)
binder/mapping.go (1)

Line range hint 137-166: Enhanced error handling in parseParamSquareBrackets.

The modifications to parseParamSquareBrackets effectively track and handle unmatched brackets, enhancing the robustness of the function. The use of bytebufferpool is efficient, and the error messages are clear.

Coverage Issue:
Please ensure that line 144 is covered by tests to maintain high code coverage.

Verification successful

Line 144 is covered by tests.

The test suite in binder/mapping_test.go includes a scenario that triggers the unmatched brackets error, confirming that line 144 is adequately covered. No further action is needed regarding test coverage for this line.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that line 144 is covered by tests.

# Test: Search for test coverage on line 144. Expect: Coverage information.
rg --type go -A 5 $'binder/mapping.go#L144'

Length of output: 42


Script:

#!/bin/bash
# Find the function definition containing line 144 in binder/mapping.go
ast-grep --lang go --pattern 'func $_($_) $_ {
  $$$
}' --json | jq -r '.matches[] | select(.range.start.line <= 144 and .range.end.line >= 144) | .text'

Length of output: 225


Script:

#!/bin/bash
# Search for test functions that call the function found in the previous step
rg --type go 'parseParamSquareBrackets' -A 10 --glob '*_test.go'

Length of output: 562


Script:

#!/bin/bash
# Extract test cases from binder/mapping_test.go to verify coverage of unmatched brackets scenario
rg --type go 'func Test' -A 20 binder/mapping_test.go

Length of output: 1239

Tools
GitHub Check: codecov/patch

[warning] 144-144: binder/mapping.go#L144
Added line #L144 was not covered by tests

binder/mapping_test.go Outdated Show resolved Hide resolved
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 40f3505 and 3b43e4f.

Files selected for processing (1)
  • binder/mapping_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • binder/mapping_test.go

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM

@ReneWerner87 ReneWerner87 added this to the v3 milestone Sep 9, 2024
@ReneWerner87 ReneWerner87 merged commit 62f66e5 into gofiber:main Sep 9, 2024
16 of 17 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 13, 2024
9 tasks
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.

🐛 [Bug]: Panic on specific query param for QueryParser
3 participants