Skip to content

Commit

Permalink
Use canInvoke
Browse files Browse the repository at this point in the history
  • Loading branch information
offirgolan committed Jan 7, 2017
1 parent 815818a commit 1b0c17d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addon/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
isEmpty,
assert,
deprecate,
canInvoke,
getProperties
} = Ember;

Expand Down Expand Up @@ -68,7 +69,7 @@ export default function validateFormat(value, options, model, attribute) {
set(options, 'regex', regex);
}

if ((isNone(value) || typeof value !== 'string') || (regex && isEmpty(value.match(regex)))) {
if (!canInvoke(value, 'match') || (regex && isEmpty(value.match(regex)))) {
return validationError(type || 'invalid', value, options);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/validators/format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ test('email', function(assert) {
'[email protected]'
];
let invalidAddresses = [
null,
undefined,
404,
'plainaddress',
'#@%^%#$@#$@#.com',
'@domain.com',
Expand Down

0 comments on commit 1b0c17d

Please sign in to comment.