From b72ed99fb88a58671982351bddaade3ccda6eaf7 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 17 Mar 2025 10:37:28 +0100 Subject: [PATCH] validate that routes are an array before merging with another Router instance --- dist/router.js | 2 ++ src/router.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/router.js b/dist/router.js index 7ea3172..94652ce 100644 --- a/dist/router.js +++ b/dist/router.js @@ -70,6 +70,8 @@ export default class Router { } use(obj) { if (obj instanceof Router) { + if (!Array.isArray(obj.routes)) + throw new TypeError("Routes must be an array."); this.routes = [...this.routes, ...obj.routes]; this.sortRoutes(); } diff --git a/src/router.ts b/src/router.ts index af92eb5..c54e199 100644 --- a/src/router.ts +++ b/src/router.ts @@ -95,6 +95,8 @@ export default class Router { */ use(obj: Router | Tpl): void { if(obj instanceof Router) { + if(!Array.isArray(obj.routes)) + throw new TypeError("Routes must be an array."); this.routes = [ ...this.routes, ...obj.routes ]; this.sortRoutes(); }