Skip to content

refactor: remove redundant character classes in slugify regex#3484

Merged
arkid15r merged 2 commits intoOWASP:mainfrom
ThetaLogN:refactor/slugify-regex-smell
Jan 23, 2026
Merged

refactor: remove redundant character classes in slugify regex#3484
arkid15r merged 2 commits intoOWASP:mainfrom
ThetaLogN:refactor/slugify-regex-smell

Conversation

@ThetaLogN
Copy link
Contributor

Resolves #3464

I have implemented a fix for this code smell identified by SonarCloud:
https://sonarcloud.io/project/issues?open=AZefK916gjv1QELYFTBo&id=OWASP_Nest

Proposed changes in frontend/src/utils/slugify.ts:

  • Change .replace(/^[-]+/, '') to .replace(/^-+/, '')
  • Change .replace(/-+$/, '') to .replace(/-+$/, '')

Checklist

  • Required: I have followed the contribution workflow
  • Required: I have verified that my code works as expected and resolves the issue.
  • Required: I ran make check-test locally: all warnings resolved, tests passed
  • I used artificial intelligence for coding, documentation, testing, or communications related to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Summary by CodeRabbit

  • Refactor
    • Optimized internal slug generation logic for improved code maintainability.

No user-facing changes in this release.

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

Walkthrough

Modified regex patterns in the slugify utility function to simplify leading and trailing hyphen trimming. Changed character class notation [-]+ to direct hyphen matching -+ in two .replace() calls, maintaining identical behavior with cleaner syntax.

Changes

Cohort / File(s) Summary
Regex Simplification
frontend/src/utils/slugify.ts
Simplified regex patterns for hyphen trimming: [-]+-+ in both leading and trailing hyphen removal calls. No behavioral change; reduces unnecessary character class syntax.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested reviewers

  • arkid15r
  • kasya
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor: remove redundant character classes in slugify regex' accurately summarizes the main change of simplifying regex patterns by removing redundant character classes.
Description check ✅ Passed The description clearly explains the fix for the SonarCloud code smell, provides specific changes being made, and shows completed checklist items validating the work.
Linked Issues check ✅ Passed The PR implementation exactly matches the requirements from issue #3464: both regex patterns have been changed from using redundant character classes [-]+ to -+ as proposed.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to the linked issue #3464; only the two regex patterns in slugify.ts were modified with no extraneous changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@arkid15r arkid15r enabled auto-merge January 22, 2026 23:24
@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.60%. Comparing base (6838e55) to head (c820292).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3484   +/-   ##
=======================================
  Coverage   85.60%   85.60%           
=======================================
  Files         461      461           
  Lines       14222    14222           
  Branches     1894     1894           
=======================================
  Hits        12175    12175           
  Misses       1678     1678           
  Partials      369      369           
Flag Coverage Δ
backend 84.47% <ø> (ø)
frontend 88.74% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6838e55...c820292. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arkid15r arkid15r added this pull request to the merge queue Jan 23, 2026
github-merge-queue bot pushed a commit that referenced this pull request Jan 23, 2026
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 23, 2026
@arkid15r arkid15r added this pull request to the merge queue Jan 23, 2026
Merged via the queue into OWASP:main with commit 7484604 Jan 23, 2026
56 of 59 checks passed
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: simplify regex in slugify utility

2 participants

Comments