Skip to content
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
2 changes: 1 addition & 1 deletion packages/next-intl/.size-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const config: SizeLimitConfig = [
{
name: "import * from 'next-intl' (react-server)",
path: 'dist/esm/production/index.react-server.js',
limit: '14.095 KB'
limit: '14.105 KB'
},
{
name: "import {createNavigation} from 'next-intl/navigation' (react-client)",
Expand Down
18 changes: 18 additions & 0 deletions packages/next-intl/src/navigation/createNavigation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,24 @@ describe.each([
);
});

it("doesn't double-encode already encoded params", () => {
const markup = renderToString(
<Link
href={{
pathname: '/news/[articleSlug]-[articleId]',
params: {
articleId: 3,
articleSlug: encodeURIComponent('launch / party')
}
}}
locale="en"
>
Create
</Link>
);
expect(markup).toContain('href="/en/news/launch%20%2F%20party-3"');
});

it('handles relative pathnames', () => {
// @ts-expect-error -- Validation is still on
const markup = renderToString(<Link href="test">Test</Link>);
Expand Down
5 changes: 1 addition & 4 deletions packages/next-intl/src/navigation/shared/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ function encodePathname(pathname: string) {
//
// Therefore, the bottom line is that next-intl should take care of encoding non-ASCII
// characters in all cases, but can rely on `new URL()` to not double-encode characters.
return pathname
.split('/')
.map((segment) => encodeURIComponent(segment))
.join('/');
return new URL(pathname, 'http://l').pathname;
}

export function getRoute<AppLocales extends Locales>(
Expand Down