Skip to content

Commit ce76e03

Browse files
committed
fully revert changes to create_manifest_data. add more docs and tests
1 parent e2ac9b6 commit ce76e03

File tree

2 files changed

+24
-11
lines changed
  • packages/kit

2 files changed

+24
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,21 @@ function get_pattern(segments, add_trailing_slash) {
393393
return part.dynamic
394394
? '([^/]+?)'
395395
: // allow users to specify characters on the file system in an encoded manner
396-
// we use [ and ] to denote parameters, so users must encode these on the file
397-
// system to match against them
398-
decodeURI(
399-
part.content
400-
// # / ? can only appear in URLs in an encoded manner
401-
// they will not be decoded by decodeURI
402-
// we skip / since you can't create a file with it on any OS
403-
.normalize()
404-
.replace(/#/g, '%23')
405-
.replace(/\?/g, '%3F')
396+
part.content
397+
.normalize()
398+
// We use [ and ] to denote parameters, so users must encode these on the file
399+
// system to match against them. We don't decode all characters since others
400+
// can already be epressed and so that '%' can be easily used directly in filenames
401+
.replace(/%5[Bb]/g, '[')
402+
.replace(/%5[Dd]/g, ']')
403+
// '#', '/', and '?' can only appear in URL path segments in an encoded manner.
404+
// They will not be touched by decodeURI so need to be encoded here, so
405+
// that we can match against them.
406+
// We skip '/' since you can't create a file with it on any OS
407+
.replace(/#/g, '%23')
408+
.replace(/\?/g, '%3F')
406409
// escape characters that have special meaning in regex
407-
).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
410+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
408411
})
409412
.join('');
410413
})

packages/kit/test/apps/basics/src/routes/encoded/_tests.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export default function (test) {
1919
assert.equal(await page.innerHTML('h3'), '/encoded/AC%2fDC: AC/DC');
2020
});
2121

22+
test('visits a route with an encoded bracket', '/encoded/%5b', async ({ page }) => {
23+
assert.equal(await page.innerHTML('h2'), '/encoded/%5b: [');
24+
assert.equal(await page.innerHTML('h3'), '/encoded/%5b: [');
25+
});
26+
27+
test('visits a route with an encoded question mark', '/encoded/%3f', async ({ page }) => {
28+
assert.equal(await page.innerHTML('h2'), '/encoded/%3f: ?');
29+
assert.equal(await page.innerHTML('h3'), '/encoded/%3f: ?');
30+
});
31+
2232
test(
2333
'visits a dynamic route with non-ASCII character',
2434
'/encoded',

0 commit comments

Comments
 (0)