Skip to content

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

FIX: Don't try to create an empty tag when updating a topic (#8481)

Jarek Radoszb5236591e9c1
diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6
index d95f8334b85..c392bc20ef6 100644
--- a/app/assets/javascripts/discourse/models/topic.js.es6
+++ b/app/assets/javascripts/discourse/models/topic.js.es6
@@ -660,8 +660,6 @@ Topic.reopenClass({
},
update(topic, props) {
- props = JSON.parse(JSON.stringify(props)) || {};
-
// We support `category_id` and `categoryId` for compatibility
if (typeof props.categoryId !== "undefined") {
props.category_id = props.categoryId;
@@ -673,11 +671,11 @@ Topic.reopenClass({
delete props.category_id;
}
- if (props.tags && props.tags.length === 0) {
- props.tags = [""];
- }
-
- return ajax(topic.get("url"), { type: "PUT", data: props }).then(result => {
+ return ajax(topic.get("url"), {
+ type: "PUT",
+ data: JSON.stringify(props),
+ contentType: "application/json"
+ }).then(result => {
// The title can be cleaned up server side
props.title = result.basic_topic.title;
props.fancy_title = result.basic_topic.fancy_title;
diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6
index 95a63b0e09f..81a530581ea 100644
--- a/test/javascripts/helpers/create-pretender.js.es6
+++ b/test/javascripts/helpers/create-pretender.js.es6
@@ -397,7 +397,13 @@ export default function() {
this.get("/t/500.json", () => response(502, {}));
this.put("/t/:slug/:id", request => {
- const data = parsePostData(request.requestBody);
+ const isJSON = request.requestHeaders["Content-Type"].includes(
+ "application/json"
+ );
+
+ const data = isJSON
+ ? JSON.parse(request.requestBody)
+ : parsePostData(request.requestBody);
return response(200, {
basic_topic: {