From 9a63d56eeed8cbdedb0699e973922d11cc060a5e Mon Sep 17 00:00:00 2001 From: Plamen Peev Date: Sun, 8 Nov 2020 12:54:50 +0200 Subject: [PATCH] Trim Whitespace From Input Fields When pasting text in the user or post fields, some unwanted whitespace may occur, especially from mobile device. Currently, if this whitespace is before the username or the post, Bibliogram returns 404. This patch prevents this by trimming the unwanted whitespace. --- src/site/api/routes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/site/api/routes.js b/src/site/api/routes.js index 9f04ce4..78f6607 100644 --- a/src/site/api/routes.js +++ b/src/site/api/routes.js @@ -71,7 +71,7 @@ module.exports = [ username = username.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\//, "") username = username.replace(/^\@+/, "") username = username.replace(/\/+$/, "") - username = username.toLowerCase() + username = username.toLowerCase().trim() return redirect(`/u/${username}`, 301) } else { return render(400, "pug/friendlyerror.pug", { @@ -264,7 +264,7 @@ module.exports = [ { route: "/p", methods: ["GET"], code: async ({url}) => { if (url.searchParams.has("p")) { - let post = url.searchParams.get("p") + let post = url.searchParams.get("p").trim() post = post.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\/p\//, "") return redirect(`/p/${post}`, 301) } else {