Skip to content

Conversation

@saichethana28
Copy link
Contributor

Proposed change

Resolves #3013

This PR updates a regular expression in
backend/apps/owasp/models/common.py to make it easier to read and maintain.

The existing pattern used [\s\S] to match any character. This has been replaced with the equivalent wildcard . , which is clearer and follows common regex best practices.

Why this change?

  • Fixes a low-severity code smell reported by SonarCloud
  • Improves readability while keeping the behaviour unchanged
  • Keeps the change small and focused on a single line

Checklist

  • Required: I read and followed the contributing guidelines
  • Required: I ran make check-test locally and all tests passed
  • I used AI for code, documentation, or tests in this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 24, 2025

Summary by CodeRabbit

  • Chores
    • Internal code optimization with no impact to user-facing functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

A regex pattern in the metadata extraction function was simplified by replacing [\s\S] with . to improve readability while maintaining identical behavior under the existing re.DOTALL flag.

Changes

Cohort / File(s) Summary
Regex simplification
backend/apps/owasp/models/common.py
Refactored get_metadata regex pattern from r"^---\s*([\s\S]*?)\s*---" to r"^---\s*(.*?)\s*---", replacing the verbose character class [\s\S] with the concise . metacharacter

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • arkid15r
  • kasya

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: refactoring a regex pattern to use a more concise wildcard syntax, which aligns with the PR's primary objective.
Description check ✅ Passed The description is directly related to the changeset, explaining the regex pattern change, the rationale (SonarCloud code smell fix), and confirming behavior remains unchanged.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #3013: replacing [\\s\\S] with . in the regex pattern in backend/apps/owasp/models/common.py to fix the SonarCloud code smell.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objective; only the regex pattern in the get_metadata function was modified with no unrelated alterations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36d4902 and c42fc94.

📒 Files selected for processing (1)
  • backend/apps/owasp/models/common.py
🔇 Additional comments (1)
backend/apps/owasp/models/common.py (1)

239-239: Regex pattern simplification is correct and improves code readability.

The change from [\s\S]*? to .*? is functionally equivalent when re.DOTALL is used (line 241), as both patterns match any character including newlines. The new pattern is more idiomatic, follows Python regex best practices, and appropriately addresses the SonarCloud code smell. Tests in backend/tests/apps/owasp/models/common_test.py validate the method works correctly with multiline YAML content.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

@saichethana28
Copy link
Contributor Author

saichethana28 commented Dec 27, 2025

Hi @arkid15r @kasya
Just checking in to see if everything looks okay with this PR or if there’s anything I should update.

@arkid15r arkid15r enabled auto-merge December 29, 2025 20:37
@arkid15r arkid15r added this pull request to the merge queue Dec 29, 2025
Merged via the queue into OWASP:main with commit 7caf577 Dec 29, 2025
26 checks passed
Mr-Rahul-Paul pushed a commit to Mr-Rahul-Paul/Nest that referenced this pull request Jan 2, 2026
arkid15r pushed a commit that referenced this pull request Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor regex in backend/apps/owasp/models/common.py to use concise syntax

2 participants