mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
Merge branch 'fix/post-length-validation' into 'develop'
Fix enforcement of character limits Closes #1618 See merge request pleroma/pleroma!2283
This commit is contained in:
commit
953aece848
2 changed files with 4 additions and 2 deletions
|
@ -591,7 +591,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
limit = Pleroma.Config.get([:instance, :limit])
|
limit = Pleroma.Config.get([:instance, :limit])
|
||||||
length = String.length(full_payload)
|
length = String.length(full_payload)
|
||||||
|
|
||||||
if length < limit do
|
if length <= limit do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
{:error, dgettext("errors", "The status is over the character limit")}
|
{:error, dgettext("errors", "The status is over the character limit")}
|
||||||
|
|
|
@ -202,13 +202,15 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
CommonAPI.post(user, %{"status" => ""})
|
CommonAPI.post(user, %{"status" => ""})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns error when character limit is exceeded" do
|
test "it validates character limits are correctly enforced" do
|
||||||
Pleroma.Config.put([:instance, :limit], 5)
|
Pleroma.Config.put([:instance, :limit], 5)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
assert {:error, "The status is over the character limit"} =
|
assert {:error, "The status is over the character limit"} =
|
||||||
CommonAPI.post(user, %{"status" => "foobar"})
|
CommonAPI.post(user, %{"status" => "foobar"})
|
||||||
|
|
||||||
|
assert {:ok, activity} = CommonAPI.post(user, %{"status" => "12345"})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it can handle activities that expire" do
|
test "it can handle activities that expire" do
|
||||||
|
|
Loading…
Reference in a new issue