Skip to content

Commit

Permalink
fix(base-driver): update dependency path-to-regexp to v8 (#20520)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Mykola Mokhnach <[email protected]>
  • Loading branch information
renovate[bot] and mykola-mokhnach authored Sep 4, 2024
1 parent 51c3063 commit 63cb664
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/base-driver/lib/express/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/base-driver/lib/protocol/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/base-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/base-driver/test/unit/express/middleware.spec.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {pathToRegexp} from 'path-to-regexp';
import {match} from 'path-to-regexp';

describe('middleware', function () {
before(async function () {
const chai = await import('chai');
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;
});
});
});

0 comments on commit 63cb664

Please sign in to comment.