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 3 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. The loop structure was altered from a conditional loop with a pre-initialized variable to an infinite loop that repeatedly searches for the next parameter start character in the pattern string. The loop now breaks when a non-zero position is found or when the end of the pattern is reached, as determined by a revised boundary check. No changes were made to the declarations of exported or public entities.

Changes

File(s) Change Summary
path.go Refactored the loop in findNextParamPosition to use an infinite loop with updated boundary checking and search logic for parameter start characters.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Path
    loop Search for next param position
        Caller->>Path: findNextParamPosition(pattern, nextParamPosition)
        Path->>Path: findNextNonEscapedCharsetPosition(subpattern)
        alt found != 0
            Path-->>Caller: return next param position
        else pattern end reached
            Path-->>Caller: break loop, return
        end
    end
Loading

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 loop once wandered, lost in the code,
Now spins forever, lightening its load.
Searching for params, it won’t miss a beat,
Until the end of the pattern, it’ll never retreat.
Hop, hop, says the rabbit, with logic so neat!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 956fd69 and 54b3b0e.

📒 Files selected for processing (1)
  • path.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • path.go

🪧 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 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

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 83.85%. Comparing base (85cce3c) to head (b6b2c7f).

Files with missing lines Patch % Lines
path.go 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3418      +/-   ##
==========================================
- Coverage   83.87%   83.85%   -0.02%     
==========================================
  Files         119      119              
  Lines       11892    11895       +3     
==========================================
+ Hits         9974     9975       +1     
- Misses       1488     1489       +1     
- Partials      430      431       +1     
Flag Coverage Δ
unittests 83.85% <80.00%> (-0.02%) ⬇️

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.

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