From 8f8ea4de92209f23e9c6ad7655ea327b8b90bb18 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli <barisusakli@gmail.com> Date: Tue, 21 Jan 2014 12:01:09 -0500 Subject: [PATCH 1/2] slug fix --- public/src/utils.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/public/src/utils.js b/public/src/utils.js index 60127dbc4f..40f74b26e1 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -102,18 +102,23 @@ invalidUnicodeChars : XRegExp('[^\\p{L}\\s\\d\\-_]', 'g'), invalidLatinChars : /[^\w\s\d\-_]/g, + trimRegex : /^\s+|\s+$/g, + collapseWhitespace : /\s+/g, + collapseDash : /-+/g, + trimTrailingDash : /-$/g, + //http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/ slugify: function(str) { - str = str.replace(/^\s+|\s+$/g, ''); // trim + str = str.replace(utils.trimRegex, ''); str = str.toLowerCase(); if(/^[\w]+$/.test(str)) { str = str.replace(utils.invalidLatinChars, '-'); } else { str = XRegExp.replace(str, utils.invalidUnicodeChars, '-'); } - str = str.replace(/\s+/g, '-') // collapse whitespace and replace by - - str = str.replace(/-+/g, '-'); // collapse dashes - str = str.replace(/-$/g, ''); + str = str.replace(utils.collapseWhitespace, '-') // collapse whitespace and replace by - + str = str.replace(utils.collapseDash, '-'); // collapse dashes + str = str.replace(utils.trimTrailingDash, ''); return str; }, @@ -206,7 +211,7 @@ if (!String.prototype.trim) { String.prototype.trim = function() { - return this.replace(/^\s+|\s+$/g, ''); + return this.replace(utils.trimRegex, ''); }; } From 74ccfd1e4d42852b7f63734fa0c7bed88c01d05e Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli <barisusakli@gmail.com> Date: Tue, 21 Jan 2014 12:02:46 -0500 Subject: [PATCH 2/2] moved islatin out too --- public/src/utils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/src/utils.js b/public/src/utils.js index 40f74b26e1..bc97257382 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -106,18 +106,19 @@ collapseWhitespace : /\s+/g, collapseDash : /-+/g, trimTrailingDash : /-$/g, + isLatin : /^[\w]+$/, //http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/ slugify: function(str) { str = str.replace(utils.trimRegex, ''); str = str.toLowerCase(); - if(/^[\w]+$/.test(str)) { + if(utils.isLatin.test(str)) { str = str.replace(utils.invalidLatinChars, '-'); } else { str = XRegExp.replace(str, utils.invalidUnicodeChars, '-'); } - str = str.replace(utils.collapseWhitespace, '-') // collapse whitespace and replace by - - str = str.replace(utils.collapseDash, '-'); // collapse dashes + str = str.replace(utils.collapseWhitespace, '-') + str = str.replace(utils.collapseDash, '-'); str = str.replace(utils.trimTrailingDash, ''); return str; },