From a08b2589d42435ee0d331abe8dff46263b71c15a Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 7 Jun 2019 14:25:42 -0400 Subject: [PATCH] FIX: removing hidden tag bumps topic when all tags are removed JS sends empty string to remove all tags. --- lib/post_revisor.rb | 2 +- spec/components/post_revisor_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 2ba445324c..7264fe2428 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -527,7 +527,7 @@ class PostRevisor modifications = post_changes.merge(@topic_changes.diff) if modifications.keys.size == 1 && tags_diff = modifications["tags"] a, b = tags_diff[0] || [], tags_diff[1] || [] - changed_tags = (a + b) - (a & b) + changed_tags = ((a + b) - (a & b)).map(&:presence).compact if (changed_tags - DiscourseTagging.hidden_tag_names(nil)).empty? return true end diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb index 95bd120208..ed4f2887e7 100644 --- a/spec/components/post_revisor_spec.rb +++ b/spec/components/post_revisor_spec.rb @@ -762,6 +762,14 @@ describe PostRevisor do }.to_not change { topic.reload.bumped_at } end + it "doesn't bump topic if empty string is given" do + topic.tags = Tag.where(name: ['important', 'secret']).to_a + expect { + result = subject.revise!(Fabricate(:admin), raw: post.raw, tags: [""]) + expect(result).to eq(true) + }.to_not change { topic.reload.bumped_at } + end + it "creates a hidden revision" do subject.revise!(Fabricate(:admin), raw: post.raw, tags: topic.tags.map(&:name) + ['secret']) expect(post.reload.revisions.first.hidden).to eq(true)