From fcb2341c212408007ce5abe54f748a78423a988b Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 25 Oct 2023 14:35:34 -0600 Subject: [PATCH] fix: Not Reconstructing Regexes. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- src/heliaFetch.ts | 4 ++-- src/heliaServer.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/heliaFetch.ts b/src/heliaFetch.ts index 01b436d..5293ff2 100644 --- a/src/heliaFetch.ts +++ b/src/heliaFetch.ts @@ -28,6 +28,7 @@ export class HeliaFetch { private fs!: UnixFS private readonly delegatedRoutingApi: string private readonly log: debug.Debugger + private readonly PARSE_PATH_REGEX = /^\/(?ip[fn]s)\/(?
[^/$]+)(?[^$]*)/ private readonly rootFilePatterns: string[] public node!: Helia public ready: Promise @@ -84,8 +85,7 @@ export class HeliaFetch { throw new Error('Path is empty') } this.log(`Parsing path: ${path}`) - const regex = /^\/(?ip[fn]s)\/(?
[^/$]+)(?[^$]*)/ - const result = path.match(regex) + const result = path.match(this.PARSE_PATH_REGEX) if (result == null || result?.groups == null) { this.log(`Error parsing path: ${path}:`, result) throw new Error(`Path: ${path} is not valid, provide path as /ipfs/ or /ipns/`) diff --git a/src/heliaServer.ts b/src/heliaServer.ts index 158ee90..dbbd381 100644 --- a/src/heliaServer.ts +++ b/src/heliaServer.ts @@ -20,6 +20,7 @@ interface RouteHandler { export class HeliaServer { private heliaFetch!: HeliaFetch private heliaVersionInfo!: { Version: string, Commit: string } + private readonly HOST_PART_REGEX = /^(?
.+)\.(?ip[fn]s)\..+$/ private readonly log: debug.Debugger public isReady: Promise public routes: RouteEntry[] @@ -81,8 +82,7 @@ export class HeliaServer { * Parses the host into its parts. */ private parseHostParts (host: string): { address: string, namespace: string } { - const hostPartsRegex = /^(?
.+)\.(?ip[fn]s)\..+$/ - const result = host.match(hostPartsRegex) + const result = host.match(this.HOST_PART_REGEX) if (result == null || result?.groups == null) { this.log(`Error parsing path: ${host}:`, result) throw new Error(`Subdomain: ${host} is not valid`)