Skip to content

A platform for community discussion. Free, open, simple.

FIX: Allow clearing tag descriptions in legacy tag update endpoint (#38405)

Natalie Tay36ac0f8ead15
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 3c499f8a7e0..b3818de2872 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -288,7 +288,7 @@ class TagsController < ::ApplicationController
previous_tag_name = @tag.name
@tag.name = DiscourseTagging.clean_tag(new_tag_name) if new_tag_name.present?
- @tag.description = new_tag_description if new_tag_description.present?
+ @tag.description = new_tag_description if new_tag.has_key?(:description)
if @tag.save
if @tag.name != previous_tag_name
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index f0434a2fe56..8679fbfcef2 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -960,6 +960,15 @@ RSpec.describe TagsController do
expect(tag.reload.description).to eq("New description")
end
+ it "can clear the tag description" do
+ tag.update!(description: "existing description")
+
+ put "/tag/#{tag.name}.json", params: { tag: { description: "" } }
+
+ expect(response.status).to eq(200)
+ expect(tag.reload.description).to be_blank
+ end
+
it "returns 403 for non-admins" do
sign_in(regular_user)
put "/tag/#{tag.name}.json", params: { tag: { description: "New description" } }