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: Network URL toPunycodeUrl preserve no path slash #29325

Merged
merged 4 commits into from
Dec 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ describe('add-ethereum-chain confirmation', () => {
"Attackers sometimes mimic sites by making small changes to the site address. Make sure you're interacting with the intended site before you continue. Punycode version: https://xn--ifura-dig.io/gnosis",
),
).toBeInTheDocument();
expect(getByText('https://iոfura.io/gnosis')).toBeInTheDocument();
});
});
});
9 changes: 6 additions & 3 deletions ui/pages/confirmations/utils/confirm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,19 @@ describe('confirm util', () => {
expect(toPunycodeURL('https://iոfura.io/gnosis')).toStrictEqual(
'https://xn--ifura-dig.io/gnosis',
);
expect(toPunycodeURL('https://www.google.com')).toStrictEqual(
'https://www.google.com/',
expect(toPunycodeURL('https://iոfura.io')).toStrictEqual(
'https://xn--ifura-dig.io',
);
expect(toPunycodeURL('https://iոfura.io/')).toStrictEqual(
'https://xn--ifura-dig.io/',
);
expect(
toPunycodeURL('https://iոfura.io/gnosis:5050?test=iոfura&foo=bar'),
).toStrictEqual(
'https://xn--ifura-dig.io/gnosis:5050?test=i%D5%B8fura&foo=bar',
);
expect(toPunycodeURL('https://www.google.com')).toStrictEqual(
'https://www.google.com/',
'https://www.google.com',
);
});
});
Expand Down
7 changes: 6 additions & 1 deletion ui/pages/confirmations/utils/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export const isValidASCIIURL = (urlString?: string) => {

export const toPunycodeURL = (urlString: string) => {
try {
return new URL(urlString).href;
const url = new URL(urlString);
const { protocol, hostname, port, search, hash } = url;
const pathname =
url.pathname === '/' && !urlString.endsWith('/') ? '' : url.pathname;

return `${protocol}//${hostname}${port}${pathname}${search}${hash}`;
} catch (err: unknown) {
console.error(`Failed to convert URL to Punycode: ${err}`);
return undefined;
Expand Down
Loading