refactor(detect): reduce complexity of parse_header_line in detect.rs#1540
Draft
github-actions[bot] wants to merge 1 commit into
Draft
refactor(detect): reduce complexity of parse_header_line in detect.rs#1540github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Extract parse_header_value helper to eliminate the nested quoted-string parser from parse_header_line. The quoted-value logic (escape handling, closing-quote scan, tail slicing) was inlined inside the source= branch, adding ~4 levels of nesting. Moving it into a dedicated private function reduces parse_header_line to a flat dispatch loop with no deep nesting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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
parse_header_lineinsrc/detect.rscontained an inline quoted-string parser directly inside thesource=match arm, adding ~4 extra levels of nesting (while loop → if-let strip_prefix → if-let strip_prefix quote → while-let char scan → if escape/quote/else).What changed
Extracted a private
parse_header_value(input: &str) -> (String, &str)helper that handles both:"parse_header_lineis now a flat dispatch loop: strip prefix → callparse_header_valueor take-until-space → advanceremaining. Maximum nesting depth drops from ~7 to ~3.Verification
parse_header_linetests pass (test_parse_header_line_*)cargo testgreen — no regressionscargo clippy --all-targets --all-features— cleanComplexity
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comSee Network Configuration for more information.