Skip to content

Commit 51474e8

Browse files
beliayeuGatsbyJS Bot
authored andcommitted
fix(gatsby): support unicode characters for 404 page (#20165)
* fix(gatsby) support unicode characters for 404 page * add case for navigating on the client for production e2e test * add similar tests for development e2e
1 parent 54b99f9 commit 51474e8

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

e2e-tests/development-runtime/cypress/integration/navigation/linking.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,26 @@ describe(`navigation`, () => {
9090
.invoke(`text`)
9191
.should(`equal`, `Hi from the second page`)
9292
})
93+
94+
it(`should show 404 page when url with unicode characters point to a non-existent page route when navigating directly`, () => {
95+
cy.visit(`/안녕404/`, {
96+
failOnStatusCode: false,
97+
}).waitForRouteChange()
98+
99+
cy.get(`h1`)
100+
.invoke(`text`)
101+
.should(`eq`, `Gatsby.js development 404 page`)
102+
})
103+
104+
it(`should show 404 page when url with unicode characters point to a non-existent page route when navigating on client`, () => {
105+
cy.visit(`/`).waitForRouteChange()
106+
cy.window()
107+
.then(win => win.___navigate(`/안녕404/`))
108+
.waitForRouteChange()
109+
110+
cy.get(`h1`)
111+
.invoke(`text`)
112+
.should(`eq`, `Gatsby.js development 404 page`)
113+
})
93114
})
94115
})

e2e-tests/production-runtime/cypress/integration/1-production.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,22 @@ describe(`Production build tests`, () => {
131131
.invoke(`text`)
132132
.should(`equal`, `Hi from the second page`)
133133
})
134+
135+
it(`should show 404 page when url with unicode characters point to a non-existent page route when navigating directly`, () => {
136+
cy.visit(`/안녕404/`, {
137+
failOnStatusCode: false,
138+
}).waitForRouteChange()
139+
140+
cy.getTestElement(`404`).should(`exist`)
141+
})
142+
143+
it(`should show 404 page when url with unicode characters point to a non-existent page route when navigating on client`, () => {
144+
cy.visit(`/`).waitForRouteChange()
145+
cy.window()
146+
.then(win => win.___navigate(`/안녕404/`))
147+
.waitForRouteChange()
148+
149+
cy.getTestElement(`404`).should(`exist`)
150+
})
134151
})
135152
})

packages/gatsby/cache-dir/production-app.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ apiRunnerAsync(`onClientEntry`).then(() => {
7272
id="gatsby-focus-wrapper"
7373
>
7474
<RouteHandler
75-
path={encodeURI(
75+
path={
7676
pageResources.page.path === `/404.html`
7777
? stripPrefix(location.pathname, __BASE_PATH__)
78-
: pageResources.page.matchPath ||
79-
pageResources.page.path
80-
)}
78+
: encodeURI(
79+
pageResources.page.matchPath ||
80+
pageResources.page.path
81+
)
82+
}
8183
{...this.props}
8284
location={location}
8385
pageResources={pageResources}

0 commit comments

Comments
 (0)