Skip to content

Commit

Permalink
fix: do not allow relative pathing without from (#1589)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
  • Loading branch information
chorobin and TkDodo committed May 13, 2024
1 parent 43a26a6 commit fd956c9
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 131 deletions.
2 changes: 1 addition & 1 deletion packages/react-router/src/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export type AbsolutePathAutoComplete<
| (TFrom extends '/'
? never
: string extends TFrom
? RemoveLeadingSlashes<RouteToPath<TRouter, TRouter['routeTree']>>
? never
: RemoveLeadingSlashes<SearchPaths<TRouter, TFrom>>)

export type RelativeToPathAutoComplete<
Expand Down
20 changes: 2 additions & 18 deletions packages/react-router/tests/Matches.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,14 @@ test('when matching a route with params', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| './'
| '../'
| '/invoices'
| '/invoices/$invoiceId'
| 'invoices'
| 'invoices/$invoiceId'
| undefined
'/' | './' | '../' | '/invoices' | '/invoices/$invoiceId' | undefined
>()

expectTypeOf(MatchRoute<DefaultRouter, any, '/invoices/$invoiceId'>)
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| './'
| '../'
| '/invoices'
| '/invoices/$invoiceId'
| 'invoices'
| 'invoices/$invoiceId'
| undefined
'/' | './' | '../' | '/invoices' | '/invoices/$invoiceId' | undefined
>()

expectTypeOf(
Expand Down
94 changes: 0 additions & 94 deletions packages/react-router/tests/link.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ test('when navigating to the root', () => {
.toEqualTypeOf<
| '../'
| './'
| ''
| '/'
| '/invoices'
| '/invoices/$invoiceId'
Expand All @@ -129,13 +128,6 @@ test('when navigating to the root', () => {
| '/invoices/$invoiceId/edit'
| '/posts'
| '/posts/$postId'
| 'invoices'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/edit'
| 'posts'
| 'posts/$postId'
| undefined
>()

Expand All @@ -145,7 +137,6 @@ test('when navigating to the root', () => {
.toEqualTypeOf<
| '../'
| './'
| ''
| '/'
| '/invoices'
| '/invoices/$invoiceId'
Expand All @@ -154,13 +145,6 @@ test('when navigating to the root', () => {
| '/invoices/$invoiceId/edit'
| '/posts'
| '/posts/$postId'
| 'invoices'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/edit'
| 'posts'
| 'posts/$postId'
| undefined
>()

Expand All @@ -170,7 +154,6 @@ test('when navigating to the root', () => {
.toEqualTypeOf<
| '../'
| './'
| ''
| '/'
| '/invoices/'
| '/invoices/$invoiceId/'
Expand All @@ -179,13 +162,6 @@ test('when navigating to the root', () => {
| '/invoices/$invoiceId/edit/'
| '/posts/'
| '/posts/$postId/'
| 'invoices/'
| 'invoices/$invoiceId/'
| 'invoices/$invoiceId/details/$detailId/'
| 'invoices/$invoiceId/details/'
| 'invoices/$invoiceId/edit/'
| 'posts/'
| 'posts/$postId/'
| undefined
>()

Expand All @@ -195,7 +171,6 @@ test('when navigating to the root', () => {
.toEqualTypeOf<
| '../'
| './'
| ''
| '/'
| '/invoices'
| '/invoices/$invoiceId'
Expand All @@ -204,13 +179,6 @@ test('when navigating to the root', () => {
| '/invoices/$invoiceId/edit'
| '/posts'
| '/posts/$postId'
| 'invoices'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/edit'
| 'posts'
| 'posts/$postId'
| undefined
>()

Expand All @@ -220,7 +188,6 @@ test('when navigating to the root', () => {
.toEqualTypeOf<
| '../'
| './'
| ''
| '/'
| '/invoices'
| '/invoices/'
Expand All @@ -236,20 +203,6 @@ test('when navigating to the root', () => {
| '/posts/'
| '/posts/$postId'
| '/posts/$postId/'
| 'invoices'
| 'invoices/'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/'
| 'invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details/$detailId/'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/details/'
| 'invoices/$invoiceId/edit'
| 'invoices/$invoiceId/edit/'
| 'posts'
| 'posts/'
| 'posts/$postId'
| 'posts/$postId/'
| undefined
>()
})
Expand Down Expand Up @@ -476,22 +429,14 @@ test('cannot navigate to a branch with an index', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| 'posts'
| '/posts'
| '/posts/$postId'
| 'posts/$postId'
| 'invoices'
| '/invoices'
| '/invoices/$invoiceId'
| '/invoices/$invoiceId/edit'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/edit'
| '/invoices/$invoiceId/details'
| '/invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/details/$detailId'
| './'
| '../'
| undefined
Expand All @@ -501,22 +446,14 @@ test('cannot navigate to a branch with an index', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| 'posts'
| '/posts'
| '/posts/$postId'
| 'posts/$postId'
| 'invoices'
| '/invoices'
| '/invoices/$invoiceId'
| '/invoices/$invoiceId/edit'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/edit'
| '/invoices/$invoiceId/details'
| '/invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/details/$detailId'
| './'
| '../'
| undefined
Expand All @@ -528,22 +465,14 @@ test('cannot navigate to a branch with an index', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| 'posts/'
| '/posts/'
| '/posts/$postId/'
| 'posts/$postId/'
| 'invoices/'
| '/invoices/'
| '/invoices/$invoiceId/'
| '/invoices/$invoiceId/edit/'
| 'invoices/$invoiceId/'
| 'invoices/$invoiceId/edit/'
| '/invoices/$invoiceId/details/'
| '/invoices/$invoiceId/details/$detailId/'
| 'invoices/$invoiceId/details/'
| 'invoices/$invoiceId/details/$detailId/'
| './'
| '../'
| undefined
Expand All @@ -553,22 +482,14 @@ test('cannot navigate to a branch with an index', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| 'posts'
| '/posts'
| '/posts/$postId'
| 'posts/$postId'
| 'invoices'
| '/invoices'
| '/invoices/$invoiceId'
| '/invoices/$invoiceId/edit'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/edit'
| '/invoices/$invoiceId/details'
| '/invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/details/$detailId'
| './'
| '../'
| undefined
Expand All @@ -580,36 +501,21 @@ test('cannot navigate to a branch with an index', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| 'posts'
| 'posts/'
| '/posts'
| '/posts/'
| '/posts/$postId'
| '/posts/$postId/'
| 'posts/$postId'
| 'posts/$postId/'
| 'invoices'
| 'invoices/'
| '/invoices'
| '/invoices/'
| '/invoices/$invoiceId'
| '/invoices/$invoiceId/'
| '/invoices/$invoiceId/edit'
| '/invoices/$invoiceId/edit/'
| 'invoices/$invoiceId'
| 'invoices/$invoiceId/'
| 'invoices/$invoiceId/edit'
| 'invoices/$invoiceId/edit/'
| '/invoices/$invoiceId/details'
| '/invoices/$invoiceId/details/'
| '/invoices/$invoiceId/details/$detailId'
| '/invoices/$invoiceId/details/$detailId/'
| 'invoices/$invoiceId/details'
| 'invoices/$invoiceId/details/'
| 'invoices/$invoiceId/details/$detailId'
| 'invoices/$invoiceId/details/$detailId/'
| './'
| '../'
| undefined
Expand Down
10 changes: 1 addition & 9 deletions packages/react-router/tests/redirects.test.-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ test('can redirect to valid route', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| 'invoices'
| '/invoices'
| '/invoices/$invoiceId'
| 'invoices/$invoiceId'
| './'
| '../'
| undefined
'/' | '/invoices' | '/invoices/$invoiceId' | './' | '../' | undefined
>()
})
10 changes: 1 addition & 9 deletions packages/react-router/tests/useNavigate.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ test('can redirect to valid route', () => {
.parameter(0)
.toHaveProperty('to')
.toEqualTypeOf<
| ''
| '/'
| 'invoices'
| '/invoices'
| '/invoices/$invoiceId'
| 'invoices/$invoiceId'
| './'
| '../'
| undefined
'/' | '/invoices' | '/invoices/$invoiceId' | './' | '../' | undefined
>()
})

0 comments on commit fd956c9

Please sign in to comment.