mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 16:17:29 +00:00
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.
This commit is contained in:
parent
e5c0c7707c
commit
9a63d56eee
@ -71,7 +71,7 @@ module.exports = [
|
|||||||
username = username.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\//, "")
|
username = username.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\//, "")
|
||||||
username = username.replace(/^\@+/, "")
|
username = username.replace(/^\@+/, "")
|
||||||
username = username.replace(/\/+$/, "")
|
username = username.replace(/\/+$/, "")
|
||||||
username = username.toLowerCase()
|
username = username.toLowerCase().trim()
|
||||||
return redirect(`/u/${username}`, 301)
|
return redirect(`/u/${username}`, 301)
|
||||||
} else {
|
} else {
|
||||||
return render(400, "pug/friendlyerror.pug", {
|
return render(400, "pug/friendlyerror.pug", {
|
||||||
@ -264,7 +264,7 @@ module.exports = [
|
|||||||
{
|
{
|
||||||
route: "/p", methods: ["GET"], code: async ({url}) => {
|
route: "/p", methods: ["GET"], code: async ({url}) => {
|
||||||
if (url.searchParams.has("p")) {
|
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\//, "")
|
post = post.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\/p\//, "")
|
||||||
return redirect(`/p/${post}`, 301)
|
return redirect(`/p/${post}`, 301)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user