Skip to content

Commit 8e03ecf

Browse files
authored
Use localeCompare instead of simple unicode point comparison (#454)
Bug: https://phabricator.wikimedia.org/T407180 Change-Id: I5bcda3b5f0dd732ac0612671987fa981c03a9bc8
1 parent c26bfb7 commit 8e03ecf

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function sortByScriptGroup( languages ) {
243243
function sortByAutonym( a, b ) {
244244
const autonymA = getAutonym( a ) || a,
245245
autonymB = getAutonym( b ) || b;
246-
return ( autonymA.toLowerCase() < autonymB.toLowerCase() ) ? -1 : 1;
246+
return autonymA.localeCompare( autonymB );
247247
}
248248

249249
/**

tests/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe( 'languagedata', () => {
153153
const languagesAM = [ 'atj', 'chr', 'chy', 'cr', 'en', 'es', 'fr', 'gn', 'haw', 'ike-cans', 'ik', 'kl', 'nl', 'pt', 'qu', 'srn', 'yi' ];
154154
assert.deepEqual(
155155
languageData.sortByScriptGroup( languagesAM.sort( languageData.sortByAutonym ) ),
156-
[ 'atj', 'gn', 'en', 'es', 'fr', 'haw', 'ik', 'kl', 'nl', 'pt', 'qu', 'srn', 'chy', 'yi', 'ike-cans', 'cr', 'chr' ],
156+
[ 'atj', 'gn', 'en', 'es', 'fr', 'haw', 'ik', 'kl', 'nl', 'pt', 'qu', 'srn', 'chy', 'yi', 'chr', 'ike-cans', 'cr' ],
157157
'languages in region AM are ordered correctly by script group'
158158
);
159159

0 commit comments

Comments
 (0)