mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Treat emoji or similar characters as one (#12482)
Long messages consisting only of emojis, dots or commas used to be valid because character-wise they were over the limit.
This commit is contained in:
@@ -52,6 +52,33 @@ describe PostValidator do
|
||||
expect(post.errors.count).to eq(1)
|
||||
end
|
||||
|
||||
it "counts emoji as a single character" do
|
||||
post.raw = ":smiling_face_with_three_hearts:" * (SiteSetting.min_post_length - 1)
|
||||
validator.stripped_length(post)
|
||||
expect(post.errors.count).to eq(1)
|
||||
|
||||
post = build(:post, topic: topic)
|
||||
post.raw = ":smiling_face_with_three_hearts:" * SiteSetting.min_post_length
|
||||
validator.stripped_length(post)
|
||||
expect(post.errors.count).to eq(0)
|
||||
end
|
||||
|
||||
it "counts multiple characters as a single character" do
|
||||
post.raw = "." * SiteSetting.min_post_length
|
||||
validator.stripped_length(post)
|
||||
expect(post.errors.count).to eq(1)
|
||||
|
||||
post = build(:post, topic: topic)
|
||||
post.raw = "," * SiteSetting.min_post_length
|
||||
validator.stripped_length(post)
|
||||
expect(post.errors.count).to eq(1)
|
||||
|
||||
post = build(:post, topic: topic)
|
||||
post.raw = "<!-- #{'very long comment' * SiteSetting.min_post_length} -->"
|
||||
validator.stripped_length(post)
|
||||
expect(post.errors.count).to eq(1)
|
||||
end
|
||||
|
||||
it "adds no error for long raw" do
|
||||
post.raw = "this is a long topic body testing 123"
|
||||
validator.stripped_length(post)
|
||||
|
||||
Reference in New Issue
Block a user