0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Deduplicate upper-/lowercase tags for posts

server side check for #2478
- added check for duplicate tags in post model
This commit is contained in:
Sebastian Gierlinger 2014-03-24 19:08:06 +01:00
parent 09b8eaf5ad
commit a3aba2d504

View file

@ -48,10 +48,21 @@ Post = ghostBookshelf.Model.extend({
saving: function (newPage, attr, options) {
/*jshint unused:false*/
var self = this;
var self = this,
tagsToCheck,
i;
// keep tags for 'saved' event
this.myTags = this.get('tags');
// keep tags for 'saved' event and deduplicate upper/lowercase tags
tagsToCheck = this.get('tags');
this.myTags = [];
_.each(tagsToCheck, function (item) {
for (i = 0; i < self.myTags.length; i = i + 1) {
if (self.myTags[i].name.toLocaleLowerCase() === item.name.toLocaleLowerCase()) {
return;
}
}
self.myTags.push(item);
});
ghostBookshelf.Model.prototype.saving.call(this);