diff --git a/slugify.js b/slugify.js index f5a6a1e..0befa5e 100644 --- a/slugify.js +++ b/slugify.js @@ -36,6 +36,8 @@ var appendChar = locale[ch]; if (appendChar === undefined) appendChar = charMap[ch]; if (appendChar === undefined) appendChar = ch; + // A null mapping (e.g. extend({ '%': null })) removes the character. + 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 e2581d2..0635c26 100644 --- a/test/slugify.js +++ b/test/slugify.js @@ -285,4 +285,16 @@ describe('slugify', () => { delete require.cache[require.resolve('../')] slugify = require('../') }) + + it('removes characters mapped to null via extend()', () => { + // https://github.com/simov/slugify/issues/177 + slugify.extend({ '|': null, '%': null, $: null }) + t.equal(slugify('100%'), '100') + t.equal(slugify('a|b$c'), 'abc') + + delete require.cache[require.resolve('../')] + slugify = require('../') + + t.equal(slugify('100%'), '100percent') + }) })