Skip to content

Commit

Permalink
Deduplicate upper-/lowercase tags for posts
Browse files Browse the repository at this point in the history
server side check for TryGhost#2478
- added check for duplicate tags in post model
  • Loading branch information
sebgie committed Mar 24, 2014
1 parent 09b8eaf commit a3aba2d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions core/server/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ Post = ghostBookshelf.Model.extend({

saving: function (newPage, attr, options) {
/*jshint unused:false*/
var self = this;

// keep tags for 'saved' event
this.myTags = this.get('tags');
var self = this,
tagsToCheck,
i;

// 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);

Expand Down

0 comments on commit a3aba2d

Please sign in to comment.