Skip to content

Commit

Permalink
fix: consolidate replacement chars from extend() (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott authored Dec 13, 2021
1 parent dff8b2f commit df7a488
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
if (localeMap[char]) {
char = localeMap[char]
} else if (opts.charmap[char]) {
char = opts.charmap[char]
char = opts.charmap[char].replace(opts.replacement, ' ')
} else if (char.includes(opts.replacement)) {
// preserve the replacement character in case it is excluded by disallowedChars
char = char.replace(opts.replacement, ' ')
Expand Down
7 changes: 7 additions & 0 deletions test/slug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,13 @@ describe('slug', function () {
assert.strictEqual(slug('फ़'), 'fhqwhgads')
})

it('consolidates repeated replacement characters from extend()', function () {
// https://github.com/simov/slugify/issues/144
assert.strictEqual(slug('day + night'), 'day-night')
slug.extend({ '+': '-' })
assert.strictEqual(slug('day + night'), 'day-night')
})

it('should ignore symbols if they are not in the charmap', function () {
assert.strictEqual(slug('unicode ♥ is ☢'), 'unicode-is')
})
Expand Down

0 comments on commit df7a488

Please sign in to comment.