1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fix Snaps view search (#14693)

Closes #14687

Snap IDs were not properly encoded (and decoded) as URI components in the Snaps view search implementation. This ensures that they are.
This commit is contained in:
Erik Marks 2022-05-11 13:14:53 -07:00 committed by GitHub
parent 9a153d2388
commit 4b2cd0ef7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 12 deletions

View File

@ -24,10 +24,7 @@ const SnapListTab = () => {
const snaps = useSelector(getSnaps);
const settingsRef = useRef();
const onClick = (snap) => {
const route = `${SNAPS_VIEW_ROUTE}/${window.btoa(
unescape(encodeURIComponent(snap.id)),
)}`;
history.push(route);
history.push(`${SNAPS_VIEW_ROUTE}/${encodeURIComponent(snap.id)}`);
};
const onToggle = (snap) => {
if (snap.enabled) {

View File

@ -32,14 +32,12 @@ function ViewSnap() {
const history = useHistory();
const location = useLocation();
const { pathname } = location;
const pathNameTail = pathname.match(/[^/]+$/u)[0];
// The snap ID is in URI-encoded form in the last path segment of the URL.
const decodedSnapId = decodeURIComponent(pathname.match(/[^/]+$/u)[0]);
const snaps = useSelector(getSnaps);
const snap = Object.entries(snaps)
.map(([_, snapState]) => snapState)
.find((snapState) => {
const decoded = decodeURIComponent(escape(window.atob(pathNameTail)));
return snapState.id === decoded;
});
.find((snapState) => snapState.id === decodedSnapId);
const [isShowingRemoveWarning, setIsShowingRemoveWarning] = useState(false);

View File

@ -717,9 +717,7 @@ export const getSnapsRouteObjects = createSelector(getSnaps, (snaps) => {
tabMessage: () => snap.manifest.proposedName,
descriptionMessage: () => snap.manifest.description,
sectionMessage: () => snap.manifest.description,
route: `${SNAPS_VIEW_ROUTE}/${window.btoa(
unescape(encodeURIComponent(snap.id)),
)}`,
route: `${SNAPS_VIEW_ROUTE}/${encodeURIComponent(snap.id)}`,
icon: 'fa fa-flask',
};
});