Skip to content

Commit

Permalink
fix pid#124; deal with custom transformations correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kbwo committed Oct 21, 2023
1 parent 563da7e commit 5d9fac2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/speakingurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,8 @@

if (typeof opts === 'object') {
maintainCase = opts.maintainCase || false;
customReplacements = (opts.custom && typeof opts.custom === 'object') ? opts.custom : customReplacements;
const customIsObject = typeof opts.custom === 'object'
customReplacements = (opts.custom && customIsObject) ? opts.custom : customReplacements;
truncate = (+opts.truncate > 1 && opts.truncate) || false;
uricFlag = opts.uric || false;
uricNoSlashFlag = opts.uricNoSlash || false;
Expand Down Expand Up @@ -1511,6 +1512,8 @@

if (v.length > 1) {
r = new RegExp('\\b' + escapeChars(v) + '\\b', 'gi');
} else if (customIsObject && /^[0-9]$/.test(v)) {
r = null
} else {
r = new RegExp(escapeChars(v), 'gi');
}
Expand Down
6 changes: 6 additions & 0 deletions test/test-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('getSlug with custom replacement', function () {
})
.should.eql('буу');

getSlug('top 100 waterfalls', {
custom: ['.']
})
.should.eql('top-100-waterfalls');


getSlug('[nodejs]', {
custom: {
'[': '[',
Expand Down

0 comments on commit 5d9fac2

Please sign in to comment.