From 1d1caada6bf542eb2ec6f0a5cb3c2e018b8db150 Mon Sep 17 00:00:00 2001 From: Xie JinBin Date: Sun, 26 Jan 2014 12:32:08 +0800 Subject: [PATCH] bug caused by unidecode's bug close #1986 - remove URL reserved chars after unidecode, because unidecode will produce some URL reserved chars. --- core/server/models/base.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/server/models/base.js b/core/server/models/base.js index e03a164c41..3fd003a010 100644 --- a/core/server/models/base.js +++ b/core/server/models/base.js @@ -213,8 +213,13 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ }); }; + slug = base.trim(); + + // Remove non ascii characters + slug = unidecode(slug); + // Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"` - slug = base.trim().replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '') + slug = slug.replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '') // Replace dots and spaces with a dash .replace(/(\s|\.)/g, '-') // Convert 2 or more dashes into a single dash @@ -224,8 +229,7 @@ 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|rss)$/g .test(slug) ? slug + '-post' : slug;