From 63cb664af13d7411ff325095cd0e9b6fd24363c3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:47:07 +0200 Subject: [PATCH] fix(base-driver): update dependency path-to-regexp to v8 (#20520) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Mykola Mokhnach --- package-lock.json | 16 ++++++++-------- packages/base-driver/lib/express/middleware.js | 4 ++-- packages/base-driver/lib/protocol/routes.js | 6 +++--- packages/base-driver/package.json | 2 +- .../test/unit/express/middleware.spec.js | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index b2f10c7a8..aa4b2de57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19403,7 +19403,7 @@ "lru-cache": "10.4.3", "method-override": "3.0.0", "morgan": "1.10.0", - "path-to-regexp": "7.1.0", + "path-to-regexp": "8.0.0", "serve-favicon": "2.5.0", "source-map-support": "0.5.21", "type-fest": "4.26.0", @@ -19433,9 +19433,9 @@ "license": "ISC" }, "packages/base-driver/node_modules/path-to-regexp": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-7.1.0.tgz", - "integrity": "sha512-ZToe+MbUF4lBqk6dV8GKot4DKfzrxXsplOddH8zN3YK+qw9/McvP7+4ICjZvOne0jQhN4eJwHsX6tT0Ns19fvw==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.0.0.tgz", + "integrity": "sha512-GAWaqWlTjYK/7SVpIUA6CTxmcg65SP30sbjdCvyYReosRkk7Z/LyHWwkK3Vu0FcIi0FNTADUs4eh1AsU5s10cg==", "license": "MIT", "engines": { "node": ">=16" @@ -20639,7 +20639,7 @@ "lru-cache": "10.4.3", "method-override": "3.0.0", "morgan": "1.10.0", - "path-to-regexp": "7.1.0", + "path-to-regexp": "8.0.0", "serve-favicon": "2.5.0", "source-map-support": "0.5.21", "spdy": "4.0.2", @@ -20661,9 +20661,9 @@ "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==" }, "path-to-regexp": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-7.1.0.tgz", - "integrity": "sha512-ZToe+MbUF4lBqk6dV8GKot4DKfzrxXsplOddH8zN3YK+qw9/McvP7+4ICjZvOne0jQhN4eJwHsX6tT0Ns19fvw==" + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.0.0.tgz", + "integrity": "sha512-GAWaqWlTjYK/7SVpIUA6CTxmcg65SP30sbjdCvyYReosRkk7Z/LyHWwkK3Vu0FcIi0FNTADUs4eh1AsU5s10cg==" }, "type-fest": { "version": "4.26.0", diff --git a/packages/base-driver/lib/express/middleware.js b/packages/base-driver/lib/express/middleware.js index b76e317e7..05f80041b 100644 --- a/packages/base-driver/lib/express/middleware.js +++ b/packages/base-driver/lib/express/middleware.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import log from './logger'; import {errors} from '../protocol'; export {handleIdempotency} from './idempotency'; -import {pathToRegexp} from 'path-to-regexp'; +import {match} from 'path-to-regexp'; import {util} from '@appium/support'; import {calcSignature} from '../helpers/session'; @@ -119,7 +119,7 @@ export function handleUpgrade(webSocketsMapping) { currentPathname = req.url ?? ''; } for (const [pathname, wsServer] of _.toPairs(webSocketsMapping)) { - if (pathToRegexp(pathname).test(currentPathname)) { + if (match(pathname)(currentPathname)) { return wsServer.handleUpgrade(req, req.socket, Buffer.from(''), (ws) => { wsServer.emit('connection', ws, req); }); diff --git a/packages/base-driver/lib/protocol/routes.js b/packages/base-driver/lib/protocol/routes.js index 0a9f2cf87..bead2e2b0 100644 --- a/packages/base-driver/lib/protocol/routes.js +++ b/packages/base-driver/lib/protocol/routes.js @@ -3,7 +3,7 @@ import _ from 'lodash'; import {util} from '@appium/support'; import {PROTOCOLS, DEFAULT_BASE_PATH} from '../constants'; -import {pathToRegexp} from 'path-to-regexp'; +import {match} from 'path-to-regexp'; const SET_ALERT_TEXT_PAYLOAD_PARAMS = { validate: (jsonObj) => @@ -952,8 +952,8 @@ export function routeToCommandName(endpoint, method, basePath = DEFAULT_BASE_PAT possiblePathnames.push(normalizedPathname); const normalizedMethod = _.toUpper(method); for (const [routePath, routeSpec] of _.toPairs(METHOD_MAP)) { - const routeRegexp = pathToRegexp(routePath); - if (possiblePathnames.some((pp) => routeRegexp.test(pp))) { + const routeMatcher = match(routePath); + if (possiblePathnames.some((pp) => routeMatcher(pp))) { const commandName = routeSpec?.[normalizedMethod]?.command; if (commandName) { return commandName; diff --git a/packages/base-driver/package.json b/packages/base-driver/package.json index 615deac41..9395c7947 100644 --- a/packages/base-driver/package.json +++ b/packages/base-driver/package.json @@ -64,7 +64,7 @@ "lru-cache": "10.4.3", "method-override": "3.0.0", "morgan": "1.10.0", - "path-to-regexp": "7.1.0", + "path-to-regexp": "8.0.0", "serve-favicon": "2.5.0", "source-map-support": "0.5.21", "type-fest": "4.26.0", diff --git a/packages/base-driver/test/unit/express/middleware.spec.js b/packages/base-driver/test/unit/express/middleware.spec.js index e9289d042..3e2c95418 100644 --- a/packages/base-driver/test/unit/express/middleware.spec.js +++ b/packages/base-driver/test/unit/express/middleware.spec.js @@ -1,4 +1,4 @@ -import {pathToRegexp} from 'path-to-regexp'; +import {match} from 'path-to-regexp'; describe('middleware', function () { before(async function () { @@ -6,19 +6,19 @@ describe('middleware', function () { chai.should(); }); - describe('pathToRegexp', function () { + describe('match', function () { it('should match static path pattern', function () { const pathname = '/ws/session/1234/appium/device/syslog'; const url = 'ws://127.0.0.1:8000/ws/session/1234/appium/device/syslog'; const currentPathname = new URL(url).pathname; - pathToRegexp(pathname).test(currentPathname).should.be.true; + match(pathname)(currentPathname).should.not.be.false; }); it('should match dynamic path pattern', function () { const pathname = '/ws/session/:sessionId/appium/device/syslog'; const url = 'ws://127.0.0.1:8000/ws/session/1234/appium/device/syslog'; const currentPathname = new URL(url).pathname; - pathToRegexp(pathname).test(currentPathname).should.be.true; + match(pathname)(currentPathname).should.not.be.false; }); }); });