From 8f095497d678c2ec3495a99ab3928748731e73ee Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Thu, 12 Sep 2024 11:14:03 -0700 Subject: [PATCH 1/2] Add error on bad input values --- index.js | 4 ++++ test.js | 6 ++++++ 2 files changed, 10 insertions(+) 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 = []; From 0c7119248b7cb528a0aea3ba45ed4e2db007cba4 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Thu, 12 Sep 2024 11:14:42 -0700 Subject: [PATCH 2/2] 0.1.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"