diff --git a/core/server/models/base.js b/core/server/models/base.js index 3b32a19c8d..bb844ab0f3 100644 --- a/core/server/models/base.js +++ b/core/server/models/base.js @@ -6,6 +6,7 @@ var ghostBookshelf, uuid = require('node-uuid'), config = require('../../../config'), Validator = require('validator').Validator, + unidecode = require('unidecode'), sanitize = require('validator').sanitize; // Initializes a new Bookshelf instance, for reference elsewhere in Ghost. @@ -125,6 +126,8 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ // Remove trailing hyphen slug = slug.charAt(slug.length - 1) === '-' ? slug.substr(0, slug.length - 1) : slug; + // Remove non ascii characters + slug = unidecode(slug); // Check the filtered slug doesn't match any of the reserved keywords slug = /^(ghost|ghost\-admin|admin|wp\-admin|wp\-login|dashboard|logout|login|signin|signup|signout|register|archive|archives|category|categories|tag|tags|page|pages|post|posts|user|users)$/g .test(slug) ? slug + '-post' : slug; diff --git a/core/test/integration/model_posts_spec.js b/core/test/integration/model_posts_spec.js index d66e5324e2..365ef018bf 100644 --- a/core/test/integration/model_posts_spec.js +++ b/core/test/integration/model_posts_spec.js @@ -228,6 +228,18 @@ describe('Post Model', function () { }).then(null, done); }); + it('can generate slugs without non-ascii characters', function (done) { + var newPost = { + title: 'भुते धडकी भरवणारा आहेत', + markdown: 'Test Content 1' + }; + + PostModel.add(newPost).then(function (createdPost) { + createdPost.get('slug').should.equal('bhute-dhddkii-bhrvnnaaraa-aahet'); + done(); + }) + }); + it('detects duplicate slugs before saving', function (done) { var firstPost = { title: 'First post', diff --git a/package.json b/package.json index 4530cc5850..e64bbe3a3c 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "showdown": "0.3.1", "sqlite3": "2.1.19", "underscore": "1.5.2", + "unidecode": "0.1.3", "validator": "1.4.0", "when": "2.5.1" },