Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6777 Fix that tag names could be blank #4892

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def commentable_owners
validates :name,
format: { with: /\A[^,,、*<>^{}=`\\%]+\z/,
message: "^Tag name '%{value}' cannot include the following restricted characters: , &#94; * < > { } = ` , 、 \\ %" }
validates :name,
format: { without: /\A\p{Cf}+\z/,
message: "^Tag name cannot be blank." }
validates :sortable_name, presence: true

validate :unwrangleable_status
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/tag_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@

Given "a zero width space tag exists" do
blank_tag = FactoryBot.build(:character, name: ["200B".hex].pack("U"))
blank_tag.save!(validate: true) # TODO: Change to validate: false when AO3-6777 is fixed
blank_tag.save!(validate: false)
end

### WHEN
Expand Down
33 changes: 33 additions & 0 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,39 @@ def expect_tag_update_flag_in_redis_to_be(flag)
expect(tag.errors[:name].join).to match(/too long/)
end

context "tags with blank names are invalid" do
[
["200B".hex].pack("U"), # zero width space
["200D".hex].pack("U"), # zero width joiner
["2060".hex].pack("U"), # word joiner
(["200B".hex].pack("U") * 3),
["200D".hex, "200D".hex, "2060".hex, "200B".hex].pack("U")
].each do |tag_name|
tag = Tag.new
tag.name = tag_name
brianjaustin marked this conversation as resolved.
Show resolved Hide resolved
it "is not saved with an error message about a blank tag" do
expect(tag.save).to be_falsey
expect(tag.errors[:name].join).to match(/cannot be blank/)
end
end
end

context "tags with names that contain some zero-width characters are valid" do
%w[
👨‍👨‍👧‍👦
ප්‍රදානය
👩‍🔬
].each do |tag_name|
tag = Tag.new
tag.name = tag_name
it "is saved" do
expect(tag.save).to be_truthy
expect(tag.errors).to be_empty
expect(tag.name).to eq(tag_name)
end
end
end

context "tags using restricted characters should not be saved" do
[
"bad, tag",
Expand Down
Loading