diff --git a/index.js b/index.js index 1150335..750c2bf 100644 --- a/index.js +++ b/index.js @@ -65,6 +65,10 @@ function pathToRegexp(path, keys, options) { return new RegExp(path.join('|'), flags); } + if (typeof path !== 'string') { + throw new TypeError('path must be a string, array of strings, or regular expression'); + } + path = path.replace( /\\.|(\/)?(\.)?:(\w+)(\(.*?\))?(\*)?(\?)?|[.*]|\/\(/g, function (match, slash, format, key, capture, star, optional, offset) { diff --git a/test.js b/test.js index 63ecb86..d239195 100644 --- a/test.js +++ b/test.js @@ -2,6 +2,12 @@ var pathToRegExp = require('./'); var assert = require('assert'); describe('path-to-regexp', function () { + it('should throw on invalid input', function () { + assert.throws(function () { + pathToRegExp(function () {}); + }, /path must be a string, array of strings, or regular expression/); + }); + describe('strings', function () { it('should match simple paths', function () { var params = [];