Skip to content

Commit 2d10ab3

Browse files
committed
revert ##2354
1 parent 4f748a9 commit 2d10ab3

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

packages/kit/src/core/create_manifest_data/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,13 @@ function get_pattern(segments, add_trailing_slash) {
389389
.map((part) => {
390390
return part.dynamic
391391
? '([^/]+?)'
392-
: encodeURIComponent(part.content.normalize()).replace(
393-
/[.*+?^${}()|[\]\\]/g,
394-
'\\$&'
395-
);
392+
: part.content
393+
.normalize()
394+
.replace(/#/g, '%23')
395+
.replace(/\?/g, '%3F')
396+
.replace(/%5B/g, '[')
397+
.replace(/%5D/g, ']')
398+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
396399
})
397400
.join('');
398401
})

packages/kit/src/core/create_manifest_data/index.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,18 @@ test('creates routes with layout', () => {
132132
]);
133133
});
134134

135-
test('encoding of characters', () => {
135+
test('encodes invalid characters', () => {
136136
const { components, routes } = create('samples/encoding');
137137

138138
// had to remove ? and " because windows
139139

140140
// const quote = 'samples/encoding/".svelte';
141141
const hash = 'samples/encoding/#.svelte';
142-
const potato = 'samples/encoding/土豆.svelte';
143142
// const question_mark = 'samples/encoding/?.svelte';
144143

145144
assert.equal(components, [
146145
layout,
147146
error,
148-
potato,
149147
// quote,
150148
hash
151149
// question_mark
@@ -154,7 +152,6 @@ test('encoding of characters', () => {
154152
assert.equal(
155153
routes.map((p) => p.pattern),
156154
[
157-
/^\/%E5%9C%9F%E8%B1%86\/?$/,
158155
// /^\/%22\/?$/,
159156
/^\/%23\/?$/
160157
// /^\/%3F\/?$/

packages/kit/src/core/create_manifest_data/test/samples/encoding/土豆.svelte

Whitespace-only changes.

packages/kit/src/runtime/client/renderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ export class Renderer {
541541
* @param {boolean} no_cache
542542
* @returns {Promise<import('./types').NavigationResult | undefined>} undefined if fallthrough
543543
*/
544-
async _load({ route, info: { path, query } }, no_cache) {
545-
const key = `${path}?${query}`;
544+
async _load({ route, info: { path, decoded_path, query } }, no_cache) {
545+
const key = `${decoded_path}?${query}`;
546546

547547
if (!no_cache) {
548548
const cached = this.cache.get(key);
@@ -552,7 +552,7 @@ export class Renderer {
552552
const [pattern, a, b, get_params] = route;
553553
const params = get_params
554554
? // the pattern is for the route which we've already matched to this path
555-
get_params(/** @type {RegExpExecArray} */ (pattern.exec(path)))
555+
get_params(/** @type {RegExpExecArray} */ (pattern.exec(decoded_path)))
556556
: {};
557557

558558
const changed = this.current.page && {

packages/kit/src/runtime/client/router.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ export class Router {
174174
if (this.owns(url)) {
175175
const path = url.pathname.slice(this.base.length) || '/';
176176

177-
const routes = this.routes.filter(([pattern]) => pattern.test(path));
177+
const decoded_path = decodeURI(path);
178+
const routes = this.routes.filter(([pattern]) => pattern.test(decoded_path));
178179

179180
const query = new URLSearchParams(url.search);
180181
const id = `${path}?${query}`;
181182

182-
return { id, routes, path, query };
183+
return { id, routes, path, decoded_path, query };
183184
}
184185
}
185186

packages/kit/src/runtime/client/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type NavigationInfo = {
55
id: string;
66
routes: CSRRoute[];
77
path: string;
8+
decoded_path: string;
89
query: URLSearchParams;
910
};
1011

packages/kit/src/runtime/server/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export async function respond(incoming, options, state = {}) {
5454
});
5555
}
5656

57+
const decoded = decodeURI(request.path);
5758
for (const route of options.manifest.routes) {
58-
const match = route.pattern.exec(request.path);
59+
const match = route.pattern.exec(decoded);
5960
if (!match) continue;
6061

6162
const response =

0 commit comments

Comments
 (0)