Skip to content

refactor(detect): reduce complexity of parse_header_line in detect.rs#1540

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-parse-header-line-22f79590b6fb0186
Draft

refactor(detect): reduce complexity of parse_header_line in detect.rs#1540
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-parse-header-line-22f79590b6fb0186

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

parse_header_line in src/detect.rs contained an inline quoted-string parser directly inside the source= 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:

  • Quoted values — scans char-by-char with backslash-escape support, returning the unescaped value and the remaining tail after the closing "
  • Unquoted values — takes up to the next space

parse_header_line is now a flat dispatch loop: strip prefix → call parse_header_value or take-until-space → advance remaining. Maximum nesting depth drops from ~7 to ~3.

Verification

  • All existing parse_header_line tests pass (test_parse_header_line_*)
  • Full cargo test green — no regressions
  • cargo clippy --all-targets --all-features — clean

Complexity

Before After
Max nesting depth ~7 ~3
Function length 59 lines 22 lines (+ 22-line helper)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · 59 AIC · ⌖ 12 AIC · ⊞ 7.2K ·

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants