diff --git a/app/serializers/post_revision_serializer.rb b/app/serializers/post_revision_serializer.rb index 543ad073a2b..5a6939dfa49 100644 --- a/app/serializers/post_revision_serializer.rb +++ b/app/serializers/post_revision_serializer.rb @@ -279,7 +279,7 @@ class PostRevisionSerializer < ApplicationSerializer end def filter_tags(tags) - tags - hidden_tags + tags.is_a?(Array) && tags.any? ? tags - hidden_tags : tags end def filter_category_id(category_id) diff --git a/spec/serializers/post_revision_serializer_spec.rb b/spec/serializers/post_revision_serializer_spec.rb index 0d526ad4b02..bea000255f5 100644 --- a/spec/serializers/post_revision_serializer_spec.rb +++ b/spec/serializers/post_revision_serializer_spec.rb @@ -41,6 +41,16 @@ RSpec.describe PostRevisionSerializer do end end + it "handles tags not being an array" do + pr = Fabricate(:post_revision, post: post, modifications: { "tags" => ["[]", ""] }) + + json = + PostRevisionSerializer.new(pr, scope: Guardian.new(Fabricate(:user)), root: false).as_json + + expect(json[:tags_changes][:previous]).to eq("[]") + expect(json[:tags_changes][:current]).to eq([]) + end + context "with hidden tags" do fab!(:public_tag) { Fabricate(:tag, name: "public") } fab!(:public_tag2) { Fabricate(:tag, name: "visible") }