Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bugs of upgrading path-to-regexp to v8.2.0 #644

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_image/docker/cello-hlf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Workdir is set to $GOPATH/src/github.com/hyperledger/fabric
# Data is stored under /var/hyperledger/production

FROM golang:1.22
FROM golang:1.23.1
LABEL maintainer="Baohua Yang <yeasy.github.com>"

# Orderer, peer, ca, operation api
Expand Down
12 changes: 6 additions & 6 deletions src/dashboard/lambda/mock/matchMock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const pathToRegexp = require('path-to-regexp');
const { pathToRegexp } = require('path-to-regexp');
const bodyParser = require('body-parser');

const mockFile = require('./index');
Expand Down Expand Up @@ -47,11 +47,11 @@ function normalizeConfig(config) {
const handler = config[key];
const { method, path } = parseKey(key);
const keys = [];
const re = pathToRegexp(path, keys);
const { regexp } = pathToRegexp(path, keys);
memo.push({
method,
path,
re,
regexp,
keys,
handler: createHandler(method, path, handler),
});
Expand Down Expand Up @@ -83,9 +83,9 @@ function matchMock(req) {
}
// eslint-disable-next-line no-restricted-syntax
for (const mock of mockData) {
const { method, re, keys } = mock;
const { method, regexp, keys } = mock;
if (method === exceptMethod) {
const match = re.exec(req.path);
const match = regexp.exec(req.path);
if (match) {
const params = {};

Expand All @@ -104,7 +104,7 @@ function matchMock(req) {
}
}

return mockData.filter(({ method, re }) => method === exceptMethod && re.test(exceptPath))[0];
return mockData.filter(({ method, regexp }) => method === exceptMethod && regexp.test(exceptPath))[0];
}
module.exports = (req, res, next) => {
const match = matchMock(req);
Expand Down
2 changes: 1 addition & 1 deletion src/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"numeral": "^2.0.6",
"nzh": "^1.0.4",
"omit.js": "^1.0.0",
"path-to-regexp": "^8.1.0",
"path-to-regexp": "^8.2.0",
"prop-types": "^15.6.2",
"qs": "^6.6.0",
"rc-animate": "^2.6.0",
Expand Down
5 changes: 3 additions & 2 deletions src/dashboard/src/components/PageHeaderWrapper/breadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import pathToRegexp from 'path-to-regexp';
import { pathToRegexp } from 'path-to-regexp';
import { Link, formatMessage } from 'umi';
import { urlToList } from '../_utils/pathTools';
import { menu } from '../../defaultSettings';
Expand Down Expand Up @@ -33,7 +33,8 @@ export const getBreadcrumb = (breadcrumbNameMap, url) => {
let breadcrumb = breadcrumbNameMap[url];
if (!breadcrumb) {
Object.keys(breadcrumbNameMap).forEach(item => {
if (pathToRegexp(item).test(url)) {
const { regexp } = pathToRegexp(item);
if (regexp.test(url)) {
breadcrumb = breadcrumbNameMap[item];
}
});
Expand Down
5 changes: 3 additions & 2 deletions src/dashboard/src/components/SiderMenu/SiderMenuUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pathToRegexp from 'path-to-regexp';
import { pathToRegexp } from 'path-to-regexp';
import { urlToList } from '../_utils/pathTools';

/**
Expand All @@ -20,7 +20,8 @@ export const getFlatMenuKeys = menuData => {
export const getMenuMatches = (flatMenuKeys, path) =>
flatMenuKeys.filter(item => {
if (item) {
return pathToRegexp(item).test(path);
const { regexp } = pathToRegexp(item);
return regexp.test(path);
}
return false;
});
Expand Down
5 changes: 3 additions & 2 deletions src/dashboard/src/pages/Authorized.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import pathToRegexp from 'path-to-regexp';
import { pathToRegexp } from 'path-to-regexp';
import { connect, Redirect } from 'umi';
import Authorized from '@/utils/Authorized';
import { getAuthority } from '@/utils/authority';
Expand All @@ -12,7 +12,8 @@ function AuthComponent({ children, location, routerData }) {
let authorities;
routeData.forEach(route => {
// match prefix
if (pathToRegexp(`${route.path}(.*)`).test(path)) {
const { regexp } = pathToRegexp(`${route.path}(.*)`);
if (regexp.test(path)) {
authorities = route.authority || authorities;

// get children authority recursively
Expand Down
8 changes: 6 additions & 2 deletions src/dashboard/src/utils/getPageTitle.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { formatMessage } from 'umi';
import pathToRegexp from 'path-to-regexp';
import { pathToRegexp } from 'path-to-regexp';
import isEqual from 'lodash/isEqual';
import memoizeOne from 'memoize-one';
import { menu, title } from '../defaultSettings';

export const matchParamsPath = (pathname, breadcrumbNameMap) => {
const pathKey = Object.keys(breadcrumbNameMap).find(key => pathToRegexp(key).test(pathname));
const pathKey = Object.keys(breadcrumbNameMap).find(key => {
const { regexp } = pathToRegexp(key);
return regexp.test(pathname);
});

return breadcrumbNameMap[pathKey];
};

Expand Down
Loading