Skip to content

Commit

Permalink
Merge d7b8697 into 66cd477
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Sep 24, 2017
2 parents 66cd477 + d7b8697 commit 0617ab8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ function percentEncode(str) {
}

function matchStringOrRegexp(target, pattern) {
var str = target && target.toString ? target.toString() : target;
var str = !_.isUndefined(target) && target.toString ? target.toString() : target;

return pattern instanceof RegExp ? str.match(pattern) : str === pattern;
return pattern instanceof RegExp ? str.match(pattern) : str === String(pattern);
}

// return [newKey, newValue]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ tap.test('deleteHeadersField deletes fields with case-insensitive field names',

});

tap.test('matchStringOrRegexp', function (t) {
tap.test('matchStringOrRegexp', {only: true}, function (t) {
t.true(common.matchStringOrRegexp('to match', 'to match'), 'true if pattern is string and target matches');
t.false(common.matchStringOrRegexp('to match', 'not to match'), 'false if pattern is string and target doesn\'t match');

t.true(common.matchStringOrRegexp(123, 123), 'true if pattern is number and target matches');

t.ok(common.matchStringOrRegexp('to match', /match/), 'match if pattern is regex and target matches');
t.false(common.matchStringOrRegexp('to match', /not/), 'false if pattern is regex and target doesn\'t match');
t.end();
Expand Down

0 comments on commit 0617ab8

Please sign in to comment.