diff --git a/slugify.js b/slugify.js index dd13ebf..a88c8e5 100644 --- a/slugify.js +++ b/slugify.js @@ -30,12 +30,13 @@ var trim = options.trim === undefined ? true : options.trim - var slug = string.normalize().split('') + var slug = Array.from(string.normalize()) // replace characters based on charMap .reduce(function (result, ch) { var appendChar = locale[ch]; if (appendChar === undefined) appendChar = charMap[ch]; if (appendChar === undefined) appendChar = ch; + if (appendChar === null) appendChar = ''; if (appendChar === replacement) appendChar = ' '; return result + appendChar // remove not allowed characters diff --git a/test/slugify.js b/test/slugify.js index 356c4b7..7a65fcf 100644 --- a/test/slugify.js +++ b/test/slugify.js @@ -285,4 +285,21 @@ describe('slugify', () => { delete require.cache[require.resolve('../')] slugify = require('../') }) + + it('handles unicode surrogate pairs', function () { + t.equal(slugify('💩'), '') + t.equal(slugify('🚀 rocket'), 'rocket') + }) + + it('supports extend with surrogate pair characters', function () { + slugify.extend({ + '💩': 'poop', + '🚀': 'rocket' + }) + + t.equal(slugify('💩 🚀'), 'poop-rocket') + + delete require.cache[require.resolve('../')] + slugify = require('../') + }) })