From 06c3e547fb0ea5ff2c3a5e88efd18327627fa92d Mon Sep 17 00:00:00 2001
From: Nutomic <me@nutomic.com>
Date: Fri, 8 Apr 2022 13:29:02 +0000
Subject: [PATCH] Dont allow community urls like /c/{id} (fixes #611) (#612)

* Dont allow community urls like /c/{id} (fixes #611)

* Also remove usage of numeric ids for user profiles

* fix

* fix
---
 src/shared/components/community/community.tsx | 17 ++++-----------
 src/shared/components/person/profile.tsx      | 21 ++-----------------
 2 files changed, 6 insertions(+), 32 deletions(-)

diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx
index da215f4..ab92308 100644
--- a/src/shared/components/community/community.tsx
+++ b/src/shared/components/community/community.tsx
@@ -166,17 +166,8 @@ export class Community extends Component<any, State> {
     let pathSplit = req.path.split("/");
     let promises: Promise<any>[] = [];
 
-    // It can be /c/main, or /c/1
-    let idOrName = pathSplit[2];
-    let id: number;
-    let name_: string;
-    if (isNaN(Number(idOrName))) {
-      name_ = idOrName;
-    } else {
-      id = Number(idOrName);
-    }
-
-    let communityForm: GetCommunity = id ? { id } : { name: name_ };
+    let communityName = pathSplit[2];
+    let communityForm: GetCommunity = { name: communityName };
     setOptionalAuth(communityForm, req.auth);
     promises.push(req.client.getCommunity(communityForm));
 
@@ -204,7 +195,7 @@ export class Community extends Component<any, State> {
         saved_only: false,
       };
       setOptionalAuth(getPostsForm, req.auth);
-      this.setName(getPostsForm, name_);
+      this.setName(getPostsForm, communityName);
       promises.push(req.client.getPosts(getPostsForm));
     } else {
       let getCommentsForm: GetComments = {
@@ -214,7 +205,7 @@ export class Community extends Component<any, State> {
         type_: ListingType.Community,
         saved_only: false,
       };
-      this.setName(getCommentsForm, name_);
+      this.setName(getCommentsForm, communityName);
       setOptionalAuth(getCommentsForm, req.auth);
       promises.push(req.client.getComments(getCommentsForm));
     }
diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx
index d94ffab..cf3e795 100644
--- a/src/shared/components/person/profile.tsx
+++ b/src/shared/components/person/profile.tsx
@@ -154,16 +154,7 @@ export class Profile extends Component<any, ProfileState> {
     let pathSplit = req.path.split("/");
     let promises: Promise<any>[] = [];
 
-    // It can be /u/me, or /username/1
-    let idOrName = pathSplit[2];
-    let person_id: number;
-    let username: string;
-    if (isNaN(Number(idOrName))) {
-      username = idOrName;
-    } else {
-      person_id = Number(idOrName);
-    }
-
+    let username = pathSplit[2];
     let view = this.getViewFromProps(pathSplit[4]);
     let sort = this.getSortTypeFromProps(pathSplit[6]);
     let page = this.getPageFromProps(Number(pathSplit[8]));
@@ -173,21 +164,13 @@ export class Profile extends Component<any, ProfileState> {
       saved_only: view === PersonDetailsView.Saved,
       page,
       limit: fetchLimit,
+      username: username,
     };
     setOptionalAuth(form, req.auth);
-    this.setIdOrName(form, person_id, username);
     promises.push(req.client.getPersonDetails(form));
     return promises;
   }
 
-  static setIdOrName(obj: any, id: number, name_: string) {
-    if (id) {
-      obj.person_id = id;
-    } else {
-      obj.username = name_;
-    }
-  }
-
   componentDidMount() {
     setupTippy();
   }
-- 
2.44.1