Repository navigation
Refactor toHexIfNeeded for better string handling - #3743
JakubOnderka wants to merge 1 commit into
Conversation
Refactor toHexIfNeeded function for improved performance and clarity.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Direct hexadecimal encoding src/utils/string.h |
toHexIfNeeded replaces std::stringstream formatting with direct string construction and lowercase hexadecimal lookup. The existing escaping conditions remain unchanged. |
Estimated code review effort: 1 (Trivial) | ~5 minutes
Change: Refactor
Possibly related issues
- owasp-modsecurity/ModSecurity#3601: The PR rewrites the same utility but preserves the
escape_speccondition, so it does not address the issue's requested call-site changes.
Suggested labels: 3.x
Suggested reviewers: eduar-hte, airween
Merge Risk: 
Minimal · up to 8a7a5
-
The refactor preserves the existing output contract and is ready to merge.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
|
There was a problem hiding this comment.
🟢 Approval recommended
The toHexIfNeeded refactor has no active review issues.
No open issues 🎉
What changed in this PR
Optimizes toHexIfNeeded, used when converting request and response bodies, by replacing stream formatting with direct string appends while preserving escaping rules and lowercase hexadecimal output.
Changes:
- Uses a hexadecimal lookup table instead of stream manipulators.
- Reserves initial output capacity based on the input size.
| File | Description |
|---|---|
src/utils/string.h |
Refactors toHexIfNeeded to reduce string-formatting overhead. |
Review effort: Balanced



what
toHexIfNeededfunction for improved performance and claritywhy
toHexIfNeededis used in converting request and response bodies, that can be pretty bigSummary by CodeRabbit