diff --git a/slugify.js b/slugify.js index dd13ebf..a286258 100644 --- a/slugify.js +++ b/slugify.js @@ -36,6 +36,7 @@ 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..0d26c97 100644 --- a/test/slugify.js +++ b/test/slugify.js @@ -285,4 +285,13 @@ describe('slugify', () => { delete require.cache[require.resolve('../')] slugify = require('../') }) + + it('should correctly handle null values in extend() as character removal', () => { + slugify.extend({ '%': null, '$': null }) + t.equal(slugify('100%'), '100') + t.equal(slugify('a$b%c'), 'abc') + + delete require.cache[require.resolve('../')] + slugify = require('../') + }) })