Skip to content

Commit

Permalink
fix: wildcard was matching unconditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeIbberson committed Dec 16, 2019
1 parent 9e161c5 commit b6fcaed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src='https://bettercodehub.com/edge/badge/MikeIbberson/comparisons?branch=master'>
</p>

<p>Currently, expressions support <code>=</code>, <code>>=</code>, <code><=</code>, <code>></code> and <code><</code> operators. Optionally, you can include a second constructor argument for changing the locale (the default is "en"). Any expressions that do not match a recognized operation get stripped out and are assumed to pass. For simply matching on exists, use the <code>=*</code> expression.</p>
<p>Currently, expressions support <code>=</code>, <code>>=</code>, <code><=</code>, <code>></code> and <code><</code> operators. Optionally, you can include a second constructor argument for changing the locale (the default is "en"). Any expressions that do not match a recognized operation get stripped out and are assumed to pass. For simply matching if a property exists, use the <code>=*</code> expression.</p>

<p>Don't worry about type casting&mdash;we'll handle that for you.</p>

Expand Down
6 changes: 6 additions & 0 deletions lib/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe('Utils', () => {

it('should return falsy on numeric mismatch', () =>
expect(Utils.equals('12', 123)).toBeFalsy());

it('should return falsy on empty', () =>
expect(Utils.equals('', '*')).toBeFalsy());

it('should return truthy on wildcard', () =>
expect(Utils.equals('a', '*')).toBeTruthy());
});

describe('isGreaterThan', () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class ValidatorRunner {
}

const equals = (a, b, locale) => {
if (b === '*') return true;
if (b === '*') return a !== '' && a !== undefined && a !== null;

return (
String(a).localeCompare(String(b), locale, {
sensitivity: 'base',
Expand Down

0 comments on commit b6fcaed

Please sign in to comment.