fix: avoid non-linear backtracking in version regex (S8786)#261
Conversation
Replace re.search with re.findall to eliminate the optional-group backtracking flagged by SonarCloud rule python:S8786. The digit-dot version regex had a theoretical O(n^2) backtracking path through the optional (?:.\d+)? group. re.findall scans linearly instead, fixing the issue with zero behavioral change.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughChangesInstalled version detection
Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #261 +/- ##
=======================================
Coverage 97.51% 97.51%
=======================================
Files 3 3
Lines 241 241
=======================================
Hits 235 235
Misses 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



Summary
SonarCloud flagged
re.searchwith a regex containing an optional group pattern as having super-linear backtracking (rulepython:S8786).Change
Replaced
re.search+ capture group withre.findallin_detect_installed_version(). Same semantics — both return the first version string found — butfindallscans linearly without backtracking through the optional(?:\.\d+)?group, which eliminates SonarCloud's concern.The function returns
Optional[str], andfindallreturns a list of strings, so the.group(1)call is replaced withmatches[0]. No behavioral change.Verification
test_util.pytests passIssue
Closes SonarCloud issue AZ82F8u7_AXk3ALWpWEQ
Summary by CodeRabbit