Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalizing unicode before transliteration #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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();
});
});