-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10293 from marmelab/fix-double-decoding-ids
Fix double decoding of ids in URLs
- Loading branch information
Showing
6 changed files
with
220 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/ra-core/src/controller/edit/useEditController.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as React from 'react'; | ||
import { Route, Routes, useLocation } from 'react-router'; | ||
import { | ||
CoreAdminContext, | ||
EditController, | ||
testDataProvider, | ||
TestMemoryRouter, | ||
} from '../..'; | ||
|
||
export default { | ||
title: 'ra-core/controller/useEditController', | ||
}; | ||
|
||
export const EncodedId = ({ | ||
id = 'test?', | ||
url = '/posts/test%3F', | ||
dataProvider = testDataProvider({ | ||
// @ts-expect-error | ||
getOne: () => Promise.resolve({ data: { id, title: 'hello' } }), | ||
}), | ||
}) => { | ||
return ( | ||
<TestMemoryRouter initialEntries={[url]}> | ||
<CoreAdminContext dataProvider={dataProvider}> | ||
<Routes> | ||
<Route | ||
path="/posts/:id" | ||
element={ | ||
<EditController resource="posts"> | ||
{({ record }) => ( | ||
<> | ||
<LocationInspector /> | ||
<p>Id: {record && record.id}</p> | ||
<p>Title: {record && record.title}</p> | ||
</> | ||
)} | ||
</EditController> | ||
} | ||
/> | ||
</Routes> | ||
</CoreAdminContext> | ||
</TestMemoryRouter> | ||
); | ||
}; | ||
|
||
export const EncodedIdWithPercentage = ({ | ||
id = 'test%', | ||
url = '/posts/test%25', | ||
dataProvider = testDataProvider({ | ||
// @ts-expect-error | ||
getOne: () => Promise.resolve({ data: { id, title: 'hello' } }), | ||
}), | ||
}) => { | ||
return ( | ||
<TestMemoryRouter initialEntries={[url]}> | ||
<CoreAdminContext dataProvider={dataProvider}> | ||
<Routes> | ||
<Route | ||
path="/posts/:id" | ||
element={ | ||
<EditController resource="posts"> | ||
{({ record }) => ( | ||
<> | ||
<LocationInspector /> | ||
<p>Id: {record && record.id}</p> | ||
<p>Title: {record && record.title}</p> | ||
</> | ||
)} | ||
</EditController> | ||
} | ||
/> | ||
</Routes> | ||
</CoreAdminContext> | ||
</TestMemoryRouter> | ||
); | ||
}; | ||
|
||
const LocationInspector = () => { | ||
const location = useLocation(); | ||
return ( | ||
<p> | ||
Location: <code>{location.pathname}</code> | ||
</p> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/ra-core/src/controller/show/useShowController.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as React from 'react'; | ||
import { Route, Routes, useLocation } from 'react-router'; | ||
import { | ||
CoreAdminContext, | ||
ShowController, | ||
testDataProvider, | ||
TestMemoryRouter, | ||
} from '../..'; | ||
|
||
export default { | ||
title: 'ra-core/controller/useShowController', | ||
}; | ||
|
||
export const EncodedId = ({ | ||
id = 'test?', | ||
url = '/posts/test%3F', | ||
dataProvider = testDataProvider({ | ||
// @ts-expect-error | ||
getOne: () => Promise.resolve({ data: { id, title: 'hello' } }), | ||
}), | ||
}) => { | ||
return ( | ||
<TestMemoryRouter initialEntries={[url]}> | ||
<CoreAdminContext dataProvider={dataProvider}> | ||
<Routes> | ||
<Route | ||
path="/posts/:id" | ||
element={ | ||
<ShowController resource="posts"> | ||
{({ record }) => ( | ||
<> | ||
<LocationInspector /> | ||
<p>Id: {record && record.id}</p> | ||
<p>Title: {record && record.title}</p> | ||
</> | ||
)} | ||
</ShowController> | ||
} | ||
/> | ||
</Routes> | ||
</CoreAdminContext> | ||
</TestMemoryRouter> | ||
); | ||
}; | ||
|
||
export const EncodedIdWithPercentage = ({ | ||
id = 'test%', | ||
url = '/posts/test%25', | ||
dataProvider = testDataProvider({ | ||
// @ts-expect-error | ||
getOne: () => Promise.resolve({ data: { id, title: 'hello' } }), | ||
}), | ||
}) => { | ||
return ( | ||
<TestMemoryRouter initialEntries={[url]}> | ||
<CoreAdminContext dataProvider={dataProvider}> | ||
<Routes> | ||
<Route | ||
path="/posts/:id" | ||
element={ | ||
<ShowController resource="posts"> | ||
{({ record }) => ( | ||
<> | ||
<LocationInspector /> | ||
<p>Id: {record && record.id}</p> | ||
<p>Title: {record && record.title}</p> | ||
</> | ||
)} | ||
</ShowController> | ||
} | ||
/> | ||
</Routes> | ||
</CoreAdminContext> | ||
</TestMemoryRouter> | ||
); | ||
}; | ||
|
||
const LocationInspector = () => { | ||
const location = useLocation(); | ||
return ( | ||
<p> | ||
Location: <code>{location.pathname}</code> | ||
</p> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters