Skip to content

Commit 26f23fa

Browse files
authored
refactor(router-core): consistent Unicode handling (#5736)
* add router-core fixes and update tests * update react-router unit tests * update react-router e2e tests * update solid-router unit tests * update solid-router e2e tests * update test description * rename function * rename test as per codeRabbit nitpick * test cleanup
1 parent 6baffeb commit 26f23fa

File tree

41 files changed

+1707
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1707
-394
lines changed

e2e/react-router/basic-file-based/src/routeTree.gen.ts

Lines changed: 81 additions & 23 deletions
Large diffs are not rendered by default.

e2e/react-router/basic-file-based/src/routes/__root.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ function RootComponent() {
130130
>
131131
relative routing
132132
</Link>{' '}
133+
<Link
134+
to="/대한민국"
135+
activeProps={{
136+
className: 'font-bold',
137+
}}
138+
>
139+
unicode path
140+
</Link>{' '}
133141
<Link
134142
// @ts-expect-error
135143
to="/this-route-does-not-exist"

e2e/react-router/basic-file-based/src/routes/params-ps/index.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ function RouteComponent() {
1818
/params-ps/named/$foo
1919
</Link>
2020
</li>
21+
<li>
22+
<Link
23+
data-testid="l-to-named-foo-special-characters"
24+
to="/params-ps/named/$foo"
25+
params={{ foo: 'foo%\\/🚀대' }}
26+
>
27+
/params-ps/named/$foo - with special characters
28+
</Link>
29+
</li>
2130
<li>
2231
<Link
2332
data-testid="l-to-named-prefixfoo"
@@ -58,6 +67,15 @@ function RouteComponent() {
5867
/params-ps/wildcard/$ with escaped params
5968
</Link>
6069
</li>
70+
<li>
71+
<Link
72+
data-testid="l-to-wildcard-encoded"
73+
to="/params-ps/wildcard/$"
74+
params={{ _splat: '%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD' }}
75+
>
76+
/params-ps/wildcard/$ with encoded params
77+
</Link>
78+
</li>
6179
<li>
6280
<Link
6381
data-testid="l-to-wildcard-prefixfoo"

e2e/react-router/basic-file-based/src/routes/params-ps/named/$foo/route.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function RouteComponent() {
3636
>
3737
Bar2
3838
</Link>
39+
<Link
40+
from={Route.fullPath}
41+
to="./$bar"
42+
params={{ bar: '🚀%2F/abc대' }}
43+
data-testid="params-foo-links-bar-special-characters"
44+
>
45+
Bar with special characters
46+
</Link>
3947
<Outlet />
4048
</div>
4149
)

e2e/react-router/basic-file-based/src/routes/search-params/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ function RouteComponent() {
2121
>
2222
go to /search-params/default?default=d2
2323
</Link>
24+
<br />
25+
<Link
26+
data-testid="link-to-default-with-search-special-characters"
27+
to="/search-params/default"
28+
search={{ default: '🚀대한민국' }}
29+
>
30+
go to /search-params/default?default=🚀대한민국
31+
</Link>
32+
<br />
33+
<Link
34+
data-testid="link-to-default-with-search-encoded-characters"
35+
to="/search-params/default"
36+
search={{ default: '%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD' }}
37+
>
38+
go to
39+
/search-params/default?default=%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD
40+
</Link>
2441
</div>
2542
)
2643
}

e2e/react-router/basic-file-based/src/routes/search-params/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createFileRoute } from '@tanstack/react-router'
22

33
export const Route = createFileRoute('/search-params')({
44
beforeLoad: async () => {
5-
await new Promise((resolve) => setTimeout(resolve, 1000))
5+
await new Promise((resolve) => setTimeout(resolve, 100))
66
return { hello: 'world' as string }
77
},
88
})

e2e/react-router/basic-file-based/src/routes/대한민국.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/대한민국')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
return (
9+
<div>
10+
<h3 className="pb-2" data-testid="unicode-heading">
11+
Hello "/대한민국"!
12+
</h3>
13+
<ul className="grid mb-2">
14+
<li>
15+
<Link
16+
data-testid="l-to-named-latin"
17+
from={Route.fullPath}
18+
to="./🚀/$id"
19+
params={{ id: 'foo' }}
20+
activeProps={{ className: 'font-bold' }}
21+
>
22+
link to latin id
23+
</Link>
24+
</li>
25+
<li>
26+
<Link
27+
data-testid="l-to-named-unicode"
28+
from={Route.fullPath}
29+
to="./🚀/$id"
30+
params={{ id: 'foo%\\/🚀대' }}
31+
activeProps={{ className: 'font-bold' }}
32+
>
33+
link to unicode id
34+
</Link>
35+
</li>
36+
<li>
37+
<Link
38+
data-testid="l-to-wildcard-latin"
39+
from={Route.fullPath}
40+
to="./wildcard/$"
41+
params={{ _splat: 'foo/bar' }}
42+
activeProps={{ className: 'font-bold' }}
43+
>
44+
link to foo/bar
45+
</Link>
46+
</li>
47+
<li>
48+
<Link
49+
data-testid="l-to-wildcard-unicode"
50+
from={Route.fullPath}
51+
to="./wildcard/$"
52+
params={{ _splat: 'foo%\\/🚀대' }}
53+
activeProps={{ className: 'font-bold' }}
54+
>
55+
link to foo%\/🚀대
56+
</Link>
57+
</li>
58+
</ul>
59+
<hr />
60+
<Outlet />
61+
</div>
62+
)
63+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/대한민국/wildcard/$')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
const params = Route.useParams()
9+
10+
return (
11+
<div>
12+
<h3 data-testid="unicode-wildcard-heading">Unicode Wildcard Params</h3>
13+
<div>
14+
Hello /대한민국/wildcard/
15+
<span data-testid="unicode-wildcard-params">{params._splat}</span>
16+
</div>
17+
</div>
18+
)
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/대한민국/🚀/$id')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
const params = Route.useParams()
9+
10+
return (
11+
<div>
12+
<h3 data-testid="unicode-named-heading">Unicode Named Params</h3>
13+
<div>
14+
Hello /대한민국/🚀/
15+
<span data-testid="unicode-named-params">{params.id}</span>
16+
</div>
17+
</div>
18+
)
19+
}

0 commit comments

Comments
 (0)