refactor: simplify isValidKeyId complexity using regex#997
Conversation
Reduced cyclomatic complexity from 20 to 8 by replacing multiple conditional branches with QRegularExpression-based validation. - Strip 0x/0X and <> prefixes with single remove() call - Check special formats (@, /, #, &) with one regex match - Validate hex string with single regex instead of loop
|
CodeAnt AI is reviewing your PR. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUtil::isValidKeyId in Changes
Sequence Diagram(s)(Skipped — changes are a focused validation refactor not requiring a multi-component sequence diagram.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/util.cpp`:
- Around line 284-285: The normalization currently uses
normalized.remove(QRegularExpression("^0[xX]|<|>$")) which fails for inputs like
"<0xABC...>" because the alternatives interfere; update the normalization logic
in src/util.cpp (the variable normalized and its QRegularExpression usage) to
first strip surrounding angle brackets then strip an optional leading 0x/0X (or
use a single regex that matches an optional leading '<' followed by an optional
0x prefix and trailing '>'), so that values like "<0xABC...>" become "ABC..."
and Pass::getRecipientList() won't drop the recipient; adjust the
QRegularExpression accordingly to reliably remove both wrappers in either order.
🪄 Autofix (Beta)
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: Repository UI (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
Run ID: 685c65ca-f308-4ad2-9025-ba34ed8e1513
📒 Files selected for processing (1)
src/util.cpp
|
CodeAnt AI finished reviewing your PR. |
Fixed regex logic error where < was unanchored, removing every < character anywhere in the string. Now strips surrounding <> first, then removes optional 0x/0X prefix.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #997 +/- ##
==========================================
- Coverage 27.17% 27.06% -0.11%
==========================================
Files 39 39
Lines 3316 3311 -5
==========================================
- Hits 901 896 -5
Misses 2415 2415
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
User description
Summary
isValidKeyIdfrom 20 to 8QRegularExpression-based validationChanges
remove()callSummary by CodeRabbit
CodeAnt-AI Description
Simplify key ID validation while keeping the same accepted formats
What Changed
Impact
✅ Consistent key ID checks✅ Fewer invalid key IDs slipping through✅ Faster key ID validation💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.