diff --git a/code/HopObject/HopObject.js b/code/HopObject/HopObject.js index d0839593..650644a9 100644 --- a/code/HopObject/HopObject.js +++ b/code/HopObject/HopObject.js @@ -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; } diff --git a/code/Tag/Tag.js b/code/Tag/Tag.js index bced404a..1a1b9cf4 100644 --- a/code/Tag/Tag.js +++ b/code/Tag/Tag.js @@ -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() {