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/package.json b/package.json index 0fe1eed..7ff5935 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "path-to-regexp", "description": "Express style path to RegExp utility", - "version": "0.1.10", + "version": "0.1.11", "files": [ "index.js", "LICENSE" 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 = [];