Skip to content

Commit

Permalink
Merge pull request #828 from node-nock/bug-827-matchStringOrRegexp
Browse files Browse the repository at this point in the history
Bug #827 Defensive coding around target
  • Loading branch information
ianwsperber committed Feb 13, 2017
2 parents 0fb8c3d + f2ae8c1 commit 7197769
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,9 @@ function percentEncode(str) {
}

function matchStringOrRegexp(target, pattern) {
if (pattern instanceof RegExp) {
return target.toString().match(pattern);
} else {
return target.toString() === pattern;
}
var str = target && target.toString ? target.toString() : target;

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

// return [newKey, newValue]
Expand Down

0 comments on commit 7197769

Please sign in to comment.