🐛 fix: prevent content-type confusion in ParseVendorSpecificContentType#198
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
📝 WalkthroughWalkthroughThis PR refactors ChangesContent Type Prefix Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.1)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
Code Review
This pull request refactors the content-type parsing logic in http.go by replacing a manual length check with a more readable strings.HasPrefix call. It also adds a new test case in http_test.go to verify the handling of vendor-specific content types with custom prefixes. I have no feedback to provide as there were no review comments to evaluate.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #198 +/- ##
=======================================
Coverage 84.15% 84.15%
=======================================
Files 14 14
Lines 1155 1155
=======================================
Hits 972 972
Misses 152 152
Partials 31 31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot Error: http.go:14:1: File is not properly formatted (gofmt) |
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness bug in ParseVendorSpecificContentType where a position/length-based “application/*” fast-path could misclassify non-application media types whose slash happened to be at the same index as "application/". The change makes the check explicit and adds a regression test to prevent reintroducing the misclassification.
Changes:
- Replace the slash-position equality check with
strings.HasPrefix(working, "application/")to only apply the known-type mapping to trueapplication/*top-level types. - Replace the length constant with a string prefix constant (
contentTypePrefixApplicationWithSlash). - Add a regression test ensuring
"aaaaaaaaaaa/vnd.api+json"is parsed as"aaaaaaaaaaa/json"(not"application/json").
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
http.go |
Tightens the application/* detection logic to an explicit prefix match to avoid top-level type confusion. |
http_test.go |
Adds a regression test covering the prior misclassification scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/gofiber/utils/sessions/93361f1e-9310-4048-aa35-41131fd60e1b Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Fixed in |
Motivation
ParseVendorSpecificContentTypethat could treat any top-level token with the same slash position asapplication/asapplication/*.Description
strings.HasPrefix(working, "application/"), change the constant tocontentTypePrefixApplicationWithSlash, and add a regression test for the inputaaaaaaaaaaa/vnd.api+jsonto ensure the original top-level type is preserved.Summary by CodeRabbit
Refactor
Tests