Skip to content

fix(trim): escape literal hyphens in custom character sets - #2949

Open
minjungsung wants to merge 1 commit into
validatorjs:masterfrom
minjungsung:fix/literal-hyphen-trimming
Open

minjungsung wants to merge 1 commit into
validatorjs:masterfrom
minjungsung:fix/literal-hyphen-trimming

Conversation

@minjungsung

Copy link
Copy Markdown

Custom trim character sets containing - are interpreted as regular expression ranges. For example, trim('--azhelloza--', 'a-z') removes letters outside the requested character set, while 'z-a' throws a SyntaxError.

Escape hyphens alongside the other regular expression metacharacters in ltrim and rtrim. This also fixes trim, which uses both sanitizers. Add regressions for both character orders and document that custom trim characters are literal.

Validation: the three new regression tests fail before the fix; npm test passes afterward (326 tests, including generated builds and ESLint).

Checklist

  • PR contains only related changes
  • README updated
  • Tests written
  • References provided where applicable: existing trim documentation and behavior of escaped metacharacters

AI assistance: implementation, tests, and this description were prepared with Codex. No human-review attestation is implied.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 00:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (e9534e1).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2949   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2599           
  Branches       658       658           
=========================================
  Hits          2599      2599           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

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.

2 participants