harden numeric constraint parsing and expand route tests#4054
harden numeric constraint parsing and expand route tests#4054ReneWerner87 merged 1 commit intomainfrom
Conversation
WalkthroughThe PR replaces silent error handling in numeric constraint validation with explicit parse error checks. When strconv.Atoi fails, constraint functions now return false immediately instead of propagating zero values. Corresponding test coverage is added for invalid metadata scenarios and range constraint edge cases. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Summary of ChangesHello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the robustness of route constraint parsing by preventing panics or incorrect matches when numeric constraint metadata is malformed. It also enhances the test suite to ensure comprehensive coverage of these new error handling mechanisms and valid numeric range scenarios, leading to more reliable and predictable routing behavior. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively hardens the numeric constraint parsing by adding error handling for malformed metadata, preventing potential panics or incorrect behavior. The accompanying test cases in path_test.go and path_testcases_test.go are well-written and provide good coverage for both invalid metadata scenarios and valid numeric range behavior. My main feedback is focused on reducing code duplication in path.go to improve maintainability, for which I've left a couple of suggestions.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4054 +/- ##
==========================================
- Coverage 91.19% 91.14% -0.06%
==========================================
Files 119 119
Lines 11146 11164 +18
==========================================
+ Hits 10165 10175 +10
- Misses 622 628 +6
- Partials 359 361 +2
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:
|
Motivation
Description
path.go,Constraint.CheckConstraintnow checksstrconv.Atoiparse errors for numeric metadata-driven constraints (minLen,maxLen,len,betweenLen,min,max,range) and returnsfalsewhen metadata cannot be parsed.Test_ConstraintCheckConstraint_InvalidMetadataand added explicit cases for invalid numeric metadata inpath_test.gocoveringminLen,maxLen,len,betweenLen,min,max, andrange.path_testcases_test.goto keep the malformed escaped-commarange(10\,30,1500)checks and add a separate validrange(10,1500)case that matches numeric parameters like25and1200.