mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 18:58:10 +00:00
FIX: Sync client & server rules regarding tag names. (#6400)
This commit is contained in:
parent
da9eee5262
commit
719a433c03
@ -220,6 +220,29 @@ export default ComboBox.extend(TagsMixin, {
|
||||
this.destroyTags(tags);
|
||||
},
|
||||
|
||||
_sanitizeContent(content, property) {
|
||||
switch (typeof content) {
|
||||
case "string":
|
||||
// See lib/discourse_tagging#clean_tag.
|
||||
return content
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/\s+/, "-")
|
||||
.replace(/[\/\?#\[\]@!\$&'\(\)\*\+,;=\.%\\`^\s|\{\}"<>]+/, "")
|
||||
.substring(0, this.siteSettings.max_tag_length);
|
||||
default:
|
||||
return get(content, this.get(property));
|
||||
}
|
||||
},
|
||||
|
||||
valueForContentItem(content) {
|
||||
return this._sanitizeContent(content, "valueAttribute");
|
||||
},
|
||||
|
||||
_nameForContent(content) {
|
||||
return this._sanitizeContent(content, "nameProperty");
|
||||
},
|
||||
|
||||
actions: {
|
||||
onSelect(tag) {
|
||||
this.set("tags", makeArray(this.get("tags")).concat(tag));
|
||||
|
@ -11,6 +11,8 @@ componentTest("default", {
|
||||
template: "{{mini-tag-chooser allowAny=true filterable=true tags=tags}}",
|
||||
|
||||
beforeEach() {
|
||||
this.siteSettings.max_tag_length = 24;
|
||||
|
||||
this.site.set("can_create_tag", true);
|
||||
this.set("tags", ["jeff", "neil", "arpit"]);
|
||||
|
||||
@ -26,7 +28,7 @@ componentTest("default", {
|
||||
});
|
||||
}
|
||||
|
||||
if (params.queryParams.q === "joffrey") {
|
||||
if (params.queryParams.q === "joffrey" || params.queryParams.q === "invalid'tag" || params.queryParams.q === "01234567890123456789012345") {
|
||||
return response({results: []});
|
||||
}
|
||||
|
||||
@ -72,6 +74,24 @@ componentTest("default", {
|
||||
"it creates the tag"
|
||||
);
|
||||
|
||||
await this.get("subject").expand();
|
||||
await this.get("subject").fillInFilter("invalid'tag");
|
||||
await this.get("subject").keyboard("enter");
|
||||
assert.deepEqual(
|
||||
this.get("tags"),
|
||||
["jeff", "neil", "arpit", "régis", "joffrey", "invalidtag"],
|
||||
"it strips invalid characters in tag"
|
||||
);
|
||||
|
||||
await this.get("subject").expand();
|
||||
await this.get("subject").fillInFilter("01234567890123456789012345");
|
||||
await this.get("subject").keyboard("enter");
|
||||
assert.deepEqual(
|
||||
this.get("tags"),
|
||||
["jeff", "neil", "arpit", "régis", "joffrey", "invalidtag"],
|
||||
"it does not allow creating long tags"
|
||||
);
|
||||
|
||||
await click(
|
||||
this.get("subject")
|
||||
.el()
|
||||
@ -80,7 +100,7 @@ componentTest("default", {
|
||||
);
|
||||
assert.deepEqual(
|
||||
this.get("tags"),
|
||||
["jeff", "neil", "arpit", "régis"],
|
||||
["jeff", "neil", "arpit", "régis", "joffrey"],
|
||||
"it removes the tag"
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user