Skip to content

Commit 01ee546

Browse files
committed
fix(client): support non-ascii locale path
1 parent 32cacb3 commit 01ee546

File tree

7 files changed

+101
-2
lines changed

7 files changed

+101
-2
lines changed

e2e/docs/.vuepress/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export default defineUserConfig({
4141
['meta', { name: 'bar', content: 'foobar zh' }],
4242
],
4343
},
44+
'/中文/': {
45+
lang: '中文',
46+
title: 'VuePress E2E',
47+
description: 'VuePress E2E 测试站点',
48+
head: [
49+
['meta', { name: 'foo-中文', content: 'foo-中文' }],
50+
['meta', { name: 'bar', content: '中文' }],
51+
],
52+
},
4453
},
4554

4655
markdown: {

e2e/docs/zh/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
foo
1+
bar

e2e/docs/中文/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
baz

e2e/tests/site-data.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,50 @@ test.describe('zh-CN', () => {
9595
await expect(fooZhLocator.first()).toHaveAttribute('content', 'foo-zh')
9696
})
9797
})
98+
99+
test.describe('non-ASCII', () => {
100+
test.beforeEach(async ({ page }) => page.goto('中文/'))
101+
102+
test('lang', async ({ page }) => {
103+
await expect(page.locator('html')).toHaveAttribute('lang', '中文')
104+
})
105+
106+
test('title', async ({ page }) => {
107+
const locator = page.locator('head title')
108+
109+
await expect(page).toHaveTitle('VuePress E2E')
110+
await expect(locator).toHaveCount(1)
111+
await expect(locator.first()).toHaveText('VuePress E2E', {
112+
useInnerText: true,
113+
})
114+
})
115+
116+
test('description', async ({ page }) => {
117+
const locator = page.locator('head meta[name="description"]')
118+
119+
await expect(locator).toHaveCount(1)
120+
await expect(locator.first()).toHaveAttribute(
121+
'content',
122+
'VuePress E2E 测试站点',
123+
)
124+
})
125+
126+
test('head', async ({ page }) => {
127+
const fooLocator = page.locator('head meta[name="foo"]')
128+
const barLocator = page.locator('head meta[name="bar"]')
129+
const bazLocator = page.locator('head meta[name="baz"]')
130+
const fooChsLocator = page.locator('head meta[name="foo-中文"]')
131+
132+
await expect(fooLocator).toHaveCount(1)
133+
await expect(fooLocator.first()).toHaveAttribute('content', 'foo')
134+
135+
await expect(barLocator).toHaveCount(1)
136+
await expect(barLocator.first()).toHaveAttribute('content', '中文')
137+
138+
await expect(bazLocator).toHaveCount(1)
139+
await expect(bazLocator.first()).toHaveAttribute('content', 'baz')
140+
141+
await expect(fooChsLocator).toHaveCount(1)
142+
await expect(fooChsLocator.first()).toHaveAttribute('content', 'foo-中文')
143+
})
144+
})

e2e/tests/update-head.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('should update head correctly', async ({ page }) => {
99
const bazLocator = page.locator('head meta[name="baz"]')
1010
const fooEnLocator = page.locator('head meta[name="foo-en"]')
1111
const fooZhLocator = page.locator('head meta[name="foo-zh"]')
12+
const fooChsLocator = page.locator('head meta[name="foo-中文"]')
1213

1314
// en-US
1415
await page.goto('')
@@ -36,6 +37,8 @@ test('should update head correctly', async ({ page }) => {
3637
await expect(bazLocator.first()).toHaveAttribute('content', 'foobar baz')
3738
await expect(fooEnLocator).toHaveCount(1)
3839
await expect(fooEnLocator.first()).toHaveAttribute('content', 'foo-en')
40+
await expect(fooZhLocator).toHaveCount(0)
41+
await expect(fooChsLocator).toHaveCount(0)
3942

4043
// navigate to zh-CN
4144
await page.locator('.e2e-theme-nav a', { hasText: 'zh-CN' }).click()
@@ -61,6 +64,37 @@ test('should update head correctly', async ({ page }) => {
6164
await expect(barLocator.first()).toHaveAttribute('content', 'foobar zh')
6265
await expect(bazLocator).toHaveCount(1)
6366
await expect(bazLocator.first()).toHaveAttribute('content', 'baz')
67+
await expect(fooEnLocator).toHaveCount(0)
6468
await expect(fooZhLocator).toHaveCount(1)
6569
await expect(fooZhLocator.first()).toHaveAttribute('content', 'foo-zh')
70+
await expect(fooChsLocator).toHaveCount(0)
71+
72+
// navigate to non-ASCII path
73+
await page.locator('.e2e-theme-nav a', { hasText: '中文' }).click()
74+
75+
// lang
76+
await expect(htmlLocator).toHaveAttribute('lang', '中文')
77+
// title
78+
await expect(page).toHaveTitle('VuePress E2E')
79+
await expect(titleLocator).toHaveCount(1)
80+
await expect(titleLocator.first()).toHaveText('VuePress E2E', {
81+
useInnerText: true,
82+
})
83+
// description
84+
await expect(descriptionLocator).toHaveCount(1)
85+
await expect(descriptionLocator.first()).toHaveAttribute(
86+
'content',
87+
'VuePress E2E 测试站点',
88+
)
89+
// head
90+
await expect(fooLocator).toHaveCount(1)
91+
await expect(fooLocator.first()).toHaveAttribute('content', 'foo')
92+
await expect(barLocator).toHaveCount(1)
93+
await expect(barLocator.first()).toHaveAttribute('content', '中文')
94+
await expect(bazLocator).toHaveCount(1)
95+
await expect(bazLocator.first()).toHaveAttribute('content', 'baz')
96+
await expect(fooEnLocator).toHaveCount(0)
97+
await expect(fooZhLocator).toHaveCount(0)
98+
await expect(fooChsLocator).toHaveCount(1)
99+
await expect(fooChsLocator.first()).toHaveAttribute('content', 'foo-中文')
66100
})

packages/client/src/resolvers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const resolvers = reactive({
9797
resolveRouteLocale: (
9898
locales: SiteData['locales'],
9999
routePath: string,
100-
): RouteLocale => resolveLocalePath(locales, routePath),
100+
): RouteLocale => resolveLocalePath(locales, decodeURI(routePath)),
101101

102102
/**
103103
* Resolve site data for specific locale

packages/core/tests/page/inferPagePath.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const app = createBaseApp({
1010
'/': {},
1111
'/en/': {},
1212
'/zh/': {},
13+
'/中文/': {},
1314
},
1415
})
1516
const appWithoutLocales = createBaseApp({
@@ -40,6 +41,13 @@ const testCases: [string, ReturnType<typeof inferPagePath>][] = [
4041
pathLocale: '/zh/',
4142
},
4243
],
44+
[
45+
'中文/foo.md',
46+
{
47+
pathInferred: '/中文/foo.html',
48+
pathLocale: '/中文/',
49+
},
50+
],
4351
]
4452

4553
describe('core > page > inferPagePath', () => {

0 commit comments

Comments
 (0)