diff --git a/core/server/utils/index.js b/core/server/utils/index.js index 8bb0d3ac29..58c15cd51d 100644 --- a/core/server/utils/index.js +++ b/core/server/utils/index.js @@ -60,8 +60,8 @@ utils = { // Remove non ascii characters string = unidecode(string); - // Replace URL reserved chars: `:/?#[]!$&()*+,;=` as well as `\%<>|^~£"` - string = string.replace(/(\s|\.|@|:|\/|\?|#|\[|\]|!|\$|&|\(|\)|\*|\+|,|;|=|\\|%|<|>|\||\^|~|"|–|—)/g, '-') + // Replace URL reserved chars: `@:/?#[]!$&()*+,;=` as well as `\%<>|^~£"{}` and \` + string = string.replace(/(\s|\.|@|:|\/|\?|#|\[|\]|!|\$|&|\(|\)|\*|\+|,|;|=|\\|%|<|>|\||\^|~|"|\{|\}|`|–|—)/g, '-') // Remove apostrophes .replace(/'/g, '') // Make the whole thing lowercase diff --git a/core/test/unit/server_utils_spec.js b/core/test/unit/server_utils_spec.js index 977905f8f7..da7ca6b4ee 100644 --- a/core/test/unit/server_utils_spec.js +++ b/core/test/unit/server_utils_spec.js @@ -35,8 +35,20 @@ describe('Server Utilities', function () { }); it('should replace most special characters with dashes', function () { - var result = safeString('a:b/c?d#e[f]g!h$i&j(k)l*m+n,o;p=q\\r%su|v^w~x£y"z@1.2', options); - result.should.equal('a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-1-2'); + var result = safeString('a:b/c?d#e[f]g!h$i&j(k)l*m+n,o;{p}=q\\r%su|v^w~x£y"z@1.2`3', options); + result.should.equal('a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-1-2-3'); + }); + + it('should replace all of the html4 compat symbols in ascii except hyphen and underscore', function () { + // note: This is missing the soft-hyphen char that isn't much-liked by linters/browsers/etc, + // it passed the test before it was removed + var result = safeString('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿'); + result.should.equal('_-c-y-ss-c-a-r-deg-23up-1o-1-41-23-4'); + }); + + it('should replace all of the foreign chars in ascii', function () { + var result = safeString('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'); + result.should.equal('aaaaaaaeceeeeiiiidnoooooxouuuuuthssaaaaaaaeceeeeiiiidnooooo-ouuuuythy'); }); it('should remove special characters at the beginning of a string', function () {