fix(core): Reduce false positives in truncateBase64 for path-like strings#1307
Conversation
…ings Raise MIN_BASE64_LENGTH_STANDALONE from 60 to 256 since truncating short strings saves negligible tokens. Require digits in isLikelyBase64 heuristic since real base64-encoded binary data virtually always contains numbers, while XPath and file path strings typically do not. Closes #1298 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe base64 truncation logic is refined to reduce false positives on path-like and XPath-like strings. The minimum standalone base64 length threshold increases from 60 to 256 characters, and the heuristic now rejects candidates lacking numeric digits before proceeding with character-type validation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Summary of ChangesHello, 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 addresses an issue where the 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. 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. Footnotes
|
⚡ Performance Benchmark
Details
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1307 +/- ##
=======================================
Coverage 87.18% 87.19%
=======================================
Files 115 115
Lines 4331 4333 +2
Branches 1007 1008 +1
=======================================
+ Hits 3776 3778 +2
Misses 555 555 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code ReviewOverall: Looks good — clean, well-scoped fix for the false positive issue reported in #1298. The two-pronged approach (threshold increase + digits requirement) is complementary and appropriate. Noteworthy ObservationsThe belt-and-suspenders approach works well here. The XPath string from #1298 ( Minor observation on Potential edge case to consider (low risk)Base64-encoded ASCII text (e.g.,
Test coverage notesGood coverage of:
One optional addition for the future: a test with a base64 string at 255 chars (just below threshold) that does contain digits, verifying it's preserved. The current "medium-length" test uses a 60-char string, so there's a gap in boundary testing from the "not truncated" side. LGTM 👍 Reviewed by Claude |
There was a problem hiding this comment.
Code Review
This pull request refines the base64 truncation logic by increasing the minimum length for standalone base64 strings to be truncated from 60 to 256 characters. It also introduces a new heuristic in the isLikelyBase64 function, requiring strings to contain digits to be considered base64, which addresses false positives for path-like or XPath strings (as reported in #1298). The changes include updated and new tests to validate these adjustments and the new truncation threshold. There are no review comments to provide feedback on.
Fixes #1298
truncateBase64was incorrectly truncating XPath and file-path strings (e.g.,postTransactionAmounts/sharesOwnedFollowingTransaction/value) by misidentifying them as standalone base64 data.Changes:
MIN_BASE64_LENGTH_STANDALONEfrom 60 to 256 — truncating short strings saves negligible tokens, and the feature targets large embedded blobsisLikelyBase64()heuristic — real base64-encoded binary data virtually always contains numbers, while path-like strings typically do notChecklist
npm run testnpm run lint