fix: prevent false port parsing when host has no colon - #245
Conversation
When the host string contains no colon, std::getline(ss, portstr, ':') assigns the entire host to portstr, causing stoi to silently parse a bogus port number (e.g. "1.2.3.4" → port=1). Add a host.find(':') != npos guard so that port parsing only occurs when a colon is actually present.
|
Warning Review limit reached
Next review available in: 44 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe URL parser now parses a port only when the host contains a colon and the extracted port is nonempty. A regression test covers bare hosts and explicit port values. ChangesURL port parsing
Estimated code review effort: 2 (Simple) | ~5 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/http.cc`:
- Line 212: Add regression tests for the host/port parsing logic surrounding the
port guard in src/http.cc, covering bare IPv4 and hostname inputs returning the
original host with port 0, plus an IPv4 address with port 9000 returning the
split host and parsed port. Verify the results through the existing parsing API
used by request and endpoint handling.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: f9f3889e-dba4-4714-bf92-fef54ebb8dfb
📒 Files selected for processing (1)
src/http.cc
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/tests.cc`:
- Around line 1572-1574: Wrap the TestUrlParse() invocation in main() with
handling for its std::runtime_error, print the failure message, and return
EXIT_FAILURE; preserve the existing success path and subsequent test execution
when no exception is thrown.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 7257dbff-2330-456f-89ad-1bce354f6301
📒 Files selected for processing (1)
tests/tests.cc
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/tests.cc`:
- Line 1558: Update the expected port in the test case for “10.0.0.1:9000” to
9000, keeping the host expectation unchanged so the corrected parser test passes
without triggering failure.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 57a96df9-b43f-4072-96c3-3d264522843c
📒 Files selected for processing (1)
tests/tests.cc
When the host string contains no colon, std::getline(ss, portstr, ':') assigns the entire host to portstr, causing stoi to silently parse a bogus port number (e.g. "1.2.3.4" → port=1). Add a host.find(':') != npos guard so that port parsing only occurs when a colon is actually present.
fix #203
Summary by CodeRabbit