Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/speakingurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,8 @@

var markChars = ['.', '!', '~', '*', "'", '(', ')'].join('');

var isNormalizeFeaturePresent = typeof ''.normalize === 'function';

/**
* getSlug
* @param {string} input input string
Expand Down Expand Up @@ -1529,6 +1531,11 @@
// escape all necessary chars
allowedChars = escapeChars(allowedChars);

// normalize unicode chars
if (isNormalizeFeaturePresent) {
input = input.normalize('NFC');
}

// trim whitespaces
input = input.replace(/(^\s+|\s+$)/g, '');

Expand Down Expand Up @@ -1686,4 +1693,4 @@
}
} catch (e) {}
}
})(this);
})(this);
22 changes: 22 additions & 0 deletions test/test-unicode-normalization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* global describe,it */

var getSlug = require('../lib/speakingurl');

describe('getSlug unicode normalization', function () {
'use strict';

it('should normalize unicode before applying transformations', function (done) {
// given
var wordWithUmlautCanonical = 'klärung';
var wordWithUmlautCombined = 'kla\u0308rung';

// when
var slugifiedCanonical = getSlug(wordWithUmlautCanonical);
var slugifiedCombined = getSlug(wordWithUmlautCombined);

// expect
getSlug(slugifiedCanonical).should.eql(slugifiedCombined);

done();
});
});