mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
Do not encode characters allowed in path when generating routes
In RFC 3986, some characters not allowed in query, which encodeURIComponent is designed for, is allowed in path. A notable example is "@", which is commonly included in paths of social profile pages. Such characters should not be encoded. The new encoding function is conforming to the RFC.
This commit is contained in:
@@ -2,6 +2,25 @@ const assert = require('assert');
|
||||
const { create_routes } = require('../../dist/core.ts.js');
|
||||
|
||||
describe('create_routes', () => {
|
||||
it('encodes caharcters not allowed in path', () => {
|
||||
const routes = create_routes({
|
||||
files: [
|
||||
'"',
|
||||
'#',
|
||||
'?'
|
||||
]
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
routes.map(r => r.pattern),
|
||||
[
|
||||
/^\/%22\/?$/,
|
||||
/^\/%23\/?$/,
|
||||
/^\/%3F\/?$/
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('sorts routes correctly', () => {
|
||||
const routes = create_routes({
|
||||
files: ['index.html', 'about.html', 'post/f[xx].html', '[wildcard].html', 'post/foo.html', 'post/[id].html', 'post/bar.html', 'post/[id].json.js']
|
||||
|
||||
Reference in New Issue
Block a user