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

Bump path-to-regexp to 8.0.0 [SECURITY] - abandoned #4074

Closed
wants to merge 16 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ This feature is built on top of the [path-to-regexp](https://www.npmjs.com/packa

- Constant path: `/orders`
- Dynamic segment: `/orders/:segment`
- Zero or more segments: `/orders{/:segment}*`
- One or more segments: `/orders{/:segment}+`
- Optional segment: `/orders{/:segment}+?`
- Optional segment: `/orders{/:segment}`
- One or more segments: `/orders/*segment`
- Zero or more segments: `/orders{/*segment}`

{{"demo": "DashboardLayoutPattern.js", "height": 400, "iframe": true}}

Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@toolpad/utils": "workspace:*",
"client-only": "^0.0.1",
"invariant": "2.2.4",
"path-to-regexp": "6.2.2",
"path-to-regexp": "8.1.0",
"prop-types": "15.8.1"
},
"devDependencies": {
Expand Down
65 changes: 58 additions & 7 deletions packages/toolpad-core/src/DashboardLayout/DashboardLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,25 @@ describe('DashboardLayout', () => {
icon: <ShoppingCartIcon />,
},
{
segment: 'reports',
title: 'Reports',
segment: 'dynamic',
title: 'Dynamic',
icon: <BarChartIcon />,
pattern: '/reports/:reportId',
pattern: '/dynamic/:dynamicId',
},
{
segment: 'oneOrMore',
title: 'One or more',
pattern: '/oneormore/*oneormoreId',
},
{
segment: 'optional',
title: 'Optional',
pattern: '/optional{/:optionalId}',
},
{
segment: 'zeroOrMore',
title: 'Zero or more',
pattern: '/zeroormore{/*zeroormoreId}',
},
];

Expand Down Expand Up @@ -241,15 +256,51 @@ describe('DashboardLayout', () => {
);
expect(within(navigation).getByRole('link', { name: 'Orders' })).toHaveClass('Mui-selected');

rerender(<AppWithPathname pathname="/reports/123" />);
rerender(<AppWithPathname pathname="/dynamic" />);
expect(within(navigation).getByRole('link', { name: 'Dynamic' })).not.toHaveClass(
'Mui-selected',
);
rerender(<AppWithPathname pathname="/dynamic/123" />);
expect(within(navigation).getByRole('link', { name: 'Dynamic' })).toHaveClass('Mui-selected');
rerender(<AppWithPathname pathname="/dynamic/123/456" />);
expect(within(navigation).getByRole('link', { name: 'Dynamic' })).not.toHaveClass(
'Mui-selected',
);

expect(within(navigation).getByRole('link', { name: 'Dashboard' })).not.toHaveClass(
rerender(<AppWithPathname pathname="/oneormore" />);
expect(within(navigation).getByRole('link', { name: 'One or more' })).not.toHaveClass(
'Mui-selected',
);
rerender(<AppWithPathname pathname="/oneormore/123" />);
expect(within(navigation).getByRole('link', { name: 'One or more' })).toHaveClass(
'Mui-selected',
);
rerender(<AppWithPathname pathname="/oneormore/123/456" />);
expect(within(navigation).getByRole('link', { name: 'One or more' })).toHaveClass(
'Mui-selected',
);

rerender(<AppWithPathname pathname="/optional" />);
expect(within(navigation).getByRole('link', { name: 'Optional' })).toHaveClass('Mui-selected');
rerender(<AppWithPathname pathname="/optional/123" />);
expect(within(navigation).getByRole('link', { name: 'Optional' })).toHaveClass('Mui-selected');
rerender(<AppWithPathname pathname="/optional/123/456" />);
expect(within(navigation).getByRole('link', { name: 'Optional' })).not.toHaveClass(
'Mui-selected',
);

rerender(<AppWithPathname pathname="/zeroormore" />);
expect(within(navigation).getByRole('link', { name: 'Zero or more' })).toHaveClass(
'Mui-selected',
);
rerender(<AppWithPathname pathname="/zeroormore/123" />);
expect(within(navigation).getByRole('link', { name: 'Zero or more' })).toHaveClass(
'Mui-selected',
);
expect(within(navigation).getByRole('link', { name: 'Orders' })).not.toHaveClass(
rerender(<AppWithPathname pathname="/zeroormore/123/456" />);
expect(within(navigation).getByRole('link', { name: 'Zero or more' })).toHaveClass(
'Mui-selected',
);
expect(within(navigation).getByRole('link', { name: 'Reports' })).toHaveClass('Mui-selected');
});

test('renders navigation actions', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-core/src/nextjs/nextCompatRouter.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'next/compat/router';
export { useRouter } from 'next/compat/router';
2 changes: 1 addition & 1 deletion packages/toolpad-core/src/nextjs/nextNavigation.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'next/navigation';
export { usePathname, useSearchParams, useRouter } from 'next/navigation';
2 changes: 1 addition & 1 deletion packages/toolpad-core/src/nextjs/nextRouter.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'next/router';
export { useRouter } from 'next/router';
5 changes: 3 additions & 2 deletions packages/toolpad-core/src/shared/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function isPageItemSelected(
pathname: string,
) {
return navigationItem.pattern
? pathToRegexp(`${basePath}${navigationItem.pattern}`).test(pathname)
? pathToRegexp(`${basePath}${navigationItem.pattern}`).regexp.test(pathname)
: getPageItemFullPath(basePath, navigationItem) === pathname;
}

Expand Down Expand Up @@ -112,7 +112,8 @@ function buildItemLookup(navigation: Navigation) {
}
map.set(path, item);
if (item.pattern) {
map.set(pathToRegexp(item.pattern), item);
const { regexp } = pathToRegexp(item.pattern);
map.set(regexp, item);
}
if (item.children) {
for (const child of item.children) {
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"node-fetch": "2.7.0",
"node-fetch-har": "1.0.1",
"open-editor": "5.0.0",
"path-to-regexp": "7.1.0",
"path-to-regexp": "8.1.0",
"perf-cascade": "3.0.3",
"pg": "8.12.0",
"piscina": "4.6.1",
Expand Down
Loading
Loading