Skip to content

Commit 8f09549

Browse files
committed
Add error on bad input values
1 parent c827fce commit 8f09549

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

index.js

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ function pathToRegexp(path, keys, options) {
6565
return new RegExp(path.join('|'), flags);
6666
}
6767

68+
if (typeof path !== 'string') {
69+
throw new TypeError('path must be a string, array of strings, or regular expression');
70+
}
71+
6872
path = path.replace(
6973
/\\.|(\/)?(\.)?:(\w+)(\(.*?\))?(\*)?(\?)?|[.*]|\/\(/g,
7074
function (match, slash, format, key, capture, star, optional, offset) {

test.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ var pathToRegExp = require('./');
22
var assert = require('assert');
33

44
describe('path-to-regexp', function () {
5+
it('should throw on invalid input', function () {
6+
assert.throws(function () {
7+
pathToRegExp(function () {});
8+
}, /path must be a string, array of strings, or regular expression/);
9+
});
10+
511
describe('strings', function () {
612
it('should match simple paths', function () {
713
var params = [];

0 commit comments

Comments
 (0)