Skip to content

Commit

Permalink
Merge pull request #232 from imbrn/fix-inefficient-case-regex
Browse files Browse the repository at this point in the history
fix inefficient regular expressions on lowercase and uppercase rules
  • Loading branch information
imbrn committed Jul 1, 2022
2 parents 472b06b + 9970ffc commit 241d302
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Inefficient regular expression complexity of lowercase() and uppercase() rules

## [1.5.0] - 2022-06-27

### Added
Expand Down
10 changes: 8 additions & 2 deletions src/v8n.js
Expand Up @@ -189,9 +189,15 @@ const availableRules = {

pattern: expected => value => expected.test(value),

lowercase: () => value => /^([a-z]+\s*)+$/.test(value),
lowercase: () => value => {
return (
typeof value === 'boolean' ||
(value === value.toLowerCase() && value.trim() !== '')
);
},

uppercase: () => value => /^([A-Z]+\s*)+$/.test(value),
uppercase: () => value =>
value === value.toUpperCase() && value.trim() !== '',

vowel: () => value => /^[aeiou]+$/i.test(value),

Expand Down

0 comments on commit 241d302

Please sign in to comment.