From c0a971848977e1f931e6c857dcf7d891e78b7c0d Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Wed, 10 Mar 2021 10:20:05 +0100 Subject: [PATCH] Add check for invalid ID --- src/scripts/classes/mapping/post.ts | 3 +++ src/scripts/classes/mapping/thread.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/scripts/classes/mapping/post.ts b/src/scripts/classes/mapping/post.ts index f9dfaaf..c8f9da5 100644 --- a/src/scripts/classes/mapping/post.ts +++ b/src/scripts/classes/mapping/post.ts @@ -101,6 +101,9 @@ export default class Post implements ILazy { // Check login if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED); + // Check ID + if (!this.id && this.id < 1) throw new Error("Invalid post ID"); + // Fetch HTML page containing the post const url = new URL(this.id.toString(), urls.POSTS).toString(); const response = await fetchHTML(url); diff --git a/src/scripts/classes/mapping/thread.ts b/src/scripts/classes/mapping/thread.ts index 40d9a87..e061a1f 100644 --- a/src/scripts/classes/mapping/thread.ts +++ b/src/scripts/classes/mapping/thread.ts @@ -230,6 +230,9 @@ export default class Thread implements ILazy { // Check login if (!shared.isLogged) throw new UserNotLogged(USER_NOT_LOGGED); + // Check ID + if (!this.id && this.id < 1) throw new Error("Invalid thread ID"); + // Prepare the url this._url = new URL(this.id.toString(), urls.THREADS).toString();