Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Fix typo and add comments, fix #10 #26

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/http/TargetExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as http from 'http';
import URL from 'url';
import ResourceIdentifier from '../ldp/IResourceIdentifier';

// TODO: This RegEx could be improved:
const VALID_HOST = /^([a-z0-9-]+\.)*[a-z0-9-]+$/;

/**
Expand All @@ -29,11 +30,13 @@ export default class TargetExtractor {
public extract(request: http.IncomingMessage): ResourceIdentifier {
// Extract path
const { pathname } = URL.parse(request.url || '');
const path = decodeURI(pathname || '/').replace(/(?<=.)\/+$/, '');
const path = decodeURIComponent(pathname || '/').replace(/(?<=.)\/+$/, '');
if (path.indexOf('/..') >= 0) {
throw new Error(`Disallowed /.. segment in URL ${pathname}`);
}
// Determine whether this is the path to an ACL resource
// Note that this enshrines certain assumptions about the server's
// system for naming ACL documents, see https://github.com/inrupt/solid-server-ts/issues/10
const isAcl = path.endsWith(this.aclExtension);

// Extract domain
Expand Down