Skip to content

🐛 fix: Handling of next param position #3418

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

KatzuYoru
Copy link

@KatzuYoru KatzuYoru commented Apr 21, 2025

PR: Fix route parameter parsing logic

  • Fixed infinite loop in findNextParamPosition function by properly recalculating the found variable on each iteration
  • Corrected boundary check to prevent index out of range errors when processing consecutive parameter characters
  • Improved consistency with other routing systems by handling multiple consecutive parameter indicators (like :::) as part of static routes rather than parameters

Fixes #3289

@KatzuYoru KatzuYoru requested a review from a team as a code owner April 21, 2025 11:52
Copy link

welcome bot commented Apr 21, 2025

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

Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

"""

Walkthrough

The changes update the logic within the findNextParamPosition function in path.go. Instead of a loop searching for the next parameter start character with a condition that caused premature breaks, the function now first finds the initial parameter start character and then iterates character-by-character to detect clusters of consecutive parameter start characters. This approach replaces the previous substring search loop with a more explicit check for consecutive parameter start characters, adjusting the returned position accordingly. No changes were made to the declarations of exported or public entities.

Changes

File(s) Change Summary
path.go Modified findNextParamPosition to detect clusters of consecutive parameter start characters by iterating character-by-character, replacing the previous substring search loop.

Assessment against linked issues

Objective Addressed Explanation
Fix ineffective loop logic in findNextParamPosition to properly skip multiple parameter characters (Issue #3289)
Ensure routes with multiple consecutive : characters (e.g., "/a:::") are handled consistently with other routers (Issue #3289)

Possibly related PRs

Suggested reviewers

  • gaby
  • sixcolors

Poem

A cluster of colons once caused dismay,
Now each is counted in a clear, bright way.
The path finds its params, no longer confused,
With logic refined, no detail’s refused.
Hop, hop, says the rabbit, with joy infused!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee012ca and 94b0b6b.

📒 Files selected for processing (1)
  • path.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • path.go
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@gaby
Copy link
Member

gaby commented Apr 21, 2025

@KatzuYoru What issue is this related to?

Copy link

codecov bot commented Apr 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.94%. Comparing base (85cce3c) to head (ee012ca).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3418      +/-   ##
==========================================
+ Coverage   83.87%   83.94%   +0.07%     
==========================================
  Files         119      119              
  Lines       11892    11898       +6     
==========================================
+ Hits         9974     9988      +14     
+ Misses       1488     1482       -6     
+ Partials      430      428       -2     
Flag Coverage Δ
unittests 83.94% <100.00%> (+0.07%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the route parameter parsing by addressing an infinite loop in findNextParamPosition and correcting boundary checks to prevent index-out-of-range issues. Key changes include:

  • Replacing the for-loop initializer with an infinite loop that recalculates the found variable on each iteration.
  • Updating the boundary check condition from "if len(pattern) > nextParamPosition" to "if len(pattern) <= nextParamPosition+1" for better index safety.

@gaby gaby changed the title fix: the non updating found 🐛 fix: Handling of next param position Apr 21, 2025
Copy link
Member

@sixcolors sixcolors left a comment

Choose a reason for hiding this comment

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

Please run the tests before submitting a PR—see make test and other targets in the Makefile. Also, make sure to update tests where necessary.

@KatzuYoru
Copy link
Author

sir the tests for path.go are passing now locally, how to check the test and coverage here?

@gaby gaby requested a review from Copilot April 26, 2025 13:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an infinite loop in the findNextParamPosition function by recalculating parameter start positions on each iteration. It also corrects the boundary check to avoid index out-of-range errors and improves the treatment of consecutive parameter indicators.

  • Fixed infinite loop in findNextParamPosition
  • Corrected boundary check for parameter clusters
  • Improved handling of consecutive parameter indicators

@gaby
Copy link
Member

gaby commented Apr 26, 2025

@KatzuYoru Check the linter failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
3 participants