Repository navigation
fix: avoid polynomial regex in routes annotation stripping - #1
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: adam@nexl.cloud <addbv2@hotmail.com>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the route annotation stripping change.
No open issues 🎉
What changed in this PR
Addresses the polynomial-regex code-scanning alert in route annotation stripping while preserving existing behavior.
Changes:
- Replaces the unanchored regex with a direct
#substring check. - Adds specs for header removal and a long whitespace-only line, including an execution-time limit.
| File | Description |
|---|---|
spec/lib/annotate/annotate_routes/helpers_spec.rb |
Adds functional and performance-regression coverage for annotation stripping. |
lib/annotate/annotate_routes/helpers.rb |
Uses include? to avoid regex backtracking when detecting the header boundary. |
Review effort: Balanced
Co-Authored-By: adam@nexl.cloud <addbv2@hotmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes code-scanning alert rb/polynomial-redos #1.
AnnotateRoutes::Helpers.strip_annotationsdecided whether a line was still part of the route-map header with the unanchoredline !~ /\s*#/, which backtracks quadratically on long whitespace runs. That regex matches exactly when the line contains#, so it becomes!line.include?('#'). The behaviour stays the same.Adds a spec for header stripping and a long whitespace line. Ran it with the existing
annotate_routes_spec.rbon Ruby 3.4 using a temporary Gemfile, because the repo's Ruby 2.7 toolchain wasn't available: 87 examples passed.Link to Devin session: https://app.devin.ai/sessions/a9787919a905463b8434939e6587f7fe
Open in Devin Desktop: https://app.devin.ai/desktop/session/a9787919a905463b8434939e6587f7fe?variant=devin