* Fixed bug that caused exception and database mess when trying to rename a tag to the same name
* Additionally, added checks to avoid inaccessible tag names
This commit is contained in:
parent
85137389c5
commit
6b00ab1fc7
2 changed files with 29 additions and 9 deletions
|
|
@ -192,8 +192,9 @@ HopObject.prototype.setTags = function(tags) {
|
|||
var diff = {};
|
||||
var tag;
|
||||
for (var i in tags) {
|
||||
// Trim and remove URL characters (like ../.. etc.)
|
||||
tag = tags[i] = String(tags[i]).trim().replace(/^[\/\.]+$/, "?");
|
||||
// Trim and remove troublesome characters (like ../.. etc.)
|
||||
// We call getAccessName with a virgin HopObject to allow most names
|
||||
tag = tags[i] = this.getAccessName.call(new HopObject, File.getName(tags[i]));
|
||||
if (tag && diff[tag] == null) {
|
||||
diff[tag] = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,18 +72,37 @@ Tag.prototype.rss_xml_action = function() {
|
|||
Tag.prototype.rename_action = function() {
|
||||
var tag = this;
|
||||
if (req.data.name) {
|
||||
tag = this.site.getTags(this.type, Tags.ALL).get(req.data.name);
|
||||
// Trim and remove troublesome characters (like ../.. etc.)
|
||||
// We call getAccessName with a virgin HopObject to allow most names
|
||||
var name = this.getAccessName.call(new HopObject, File.getName(req.data.name));
|
||||
tag = this.site.getTags(this.type, Tags.ALL).get(name);
|
||||
if (!tag) {
|
||||
tag = new Tag(req.data.name, this.site, this.type);
|
||||
tag = new Tag(name, this.site, this.type);
|
||||
this.site.$tags.add(tag);
|
||||
}
|
||||
this.forEach(function() {
|
||||
this.tag_id = tag._id;
|
||||
});
|
||||
this.remove();
|
||||
res.commit();
|
||||
if (tag !== this) {
|
||||
this.forEach(function() {
|
||||
this.tag_id = tag._id;
|
||||
});
|
||||
this.remove();
|
||||
res.commit();
|
||||
}
|
||||
}
|
||||
res.redirect(tag.href());
|
||||
return;
|
||||
|
||||
// FIXME: Actually, the method should work like this but it caused a mess:
|
||||
if (req.data.name) {
|
||||
var name = this.getAccessName.call(new HopObject, File.getName(req.data.name));
|
||||
var tag = this.site.getTags(this.type, Tags.ALL).get(name);
|
||||
if (tag) {
|
||||
if (tag !== this) {
|
||||
// move tagged items to tag like above
|
||||
}
|
||||
} else {
|
||||
// rename tag like: this.name = name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Tag.prototype.delete_action = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue