Add regex caching and pattern validation to trim methods#7803
Draft
Add regex caching and pattern validation to trim methods#7803
Conversation
b8a63ac to
e2835f4
Compare
- Add pattern length validation (max 100 chars) to prevent DoS attacks - Implement regex caching using std::sync::OnceLock and parking_lot::Mutex - Apply security fixes to trim_start_pattern and trim_end_pattern functions - Add parking_lot dependency to string_wizard crate Co-authored-by: IWANABETHATGUY <[email protected]>
Base automatically changed from
01-08-feat_nativemagicstring_trim_methods
to
main
January 8, 2026 10:36
- Eliminate unnecessary clone in get_cached_regex - Add documentation about cache size bounds - Add security notes about ReDoS risks in function docs Co-authored-by: IWANABETHATGUY <[email protected]>
Replace direct Regex clones with Arc<Regex> to avoid expensive cloning of compiled state machines. Arc::clone only increments a reference count, avoiding the need to clone the compiled regex. Co-authored-by: IWANABETHATGUY <[email protected]>
Copilot
AI
changed the title
[WIP] Update nativeMagicString trim methods based on feedback
Add regex caching and pattern validation to trim methods
Jan 8, 2026
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for rolldown-rs canceled.
|
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.
Addresses security and performance issues in
trim_start_patternandtrim_end_patternwhere regex compilation occurs on every call with unbounded user input.Changes
OnceLock<Mutex<HashMap<String, Arc<Regex>>>>to avoid recompiling identical patternsImplementation
Cache is naturally bounded by pattern length limit and typical usage (primarily
\sand[\r\n]patterns hit fast paths).💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.