mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Allow URLs with multiple leading slashes.
Fixes https://github.com/solid/community-server/issues/1025
This commit is contained in:
parent
2e4589938f
commit
b42150cf52
@ -45,12 +45,11 @@ export class OriginalUrlExtractor extends TargetExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// URL object applies punycode encoding to domain
|
// URL object applies punycode encoding to domain
|
||||||
const base = `${protocol}://${host}`;
|
const originalUrl = new URL(`${protocol}://${host}`);
|
||||||
const originalUrl = new URL(toCanonicalUriPath(url), base);
|
const [ , pathname, search ] = /^([^?]*)(.*)/u.exec(toCanonicalUriPath(url))!;
|
||||||
|
originalUrl.pathname = pathname;
|
||||||
// Drop the query string if requested
|
if (this.includeQueryString && search) {
|
||||||
if (!this.includeQueryString) {
|
originalUrl.search = search;
|
||||||
originalUrl.search = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { path: originalUrl.href };
|
return { path: originalUrl.href };
|
||||||
|
@ -32,6 +32,12 @@ describe('A OriginalUrlExtractor', (): void => {
|
|||||||
.resolves.toEqual({ path: 'http://test.com/url' });
|
.resolves.toEqual({ path: 'http://test.com/url' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns an input URL with multiple leading slashes.', async(): Promise<void> => {
|
||||||
|
const noQuery = new OriginalUrlExtractor({ includeQueryString: true });
|
||||||
|
await expect(noQuery.handle({ request: { url: '///url?abc=def&xyz', headers: { host: 'test.com' }} as any }))
|
||||||
|
.resolves.toEqual({ path: 'http://test.com///url?abc=def&xyz' });
|
||||||
|
});
|
||||||
|
|
||||||
it('drops the query string when includeQueryString is set to false.', async(): Promise<void> => {
|
it('drops the query string when includeQueryString is set to false.', async(): Promise<void> => {
|
||||||
await expect(extractor.handle({ request: { url: '/url?abc=def&xyz', headers: { host: 'test.com' }} as any }))
|
await expect(extractor.handle({ request: { url: '/url?abc=def&xyz', headers: { host: 'test.com' }} as any }))
|
||||||
.resolves.toEqual({ path: 'http://test.com/url?abc=def&xyz' });
|
.resolves.toEqual({ path: 'http://test.com/url?abc=def&xyz' });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user