From fd8d3abec8f2b02f6b77e65b6f643f808cc1d8a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 5 Aug 2016 20:01:17 +0200 Subject: [PATCH] jquery.tablesorter: Handle more than single characters in 'tableSorterCollation' The code that uses this will already work fine, we only need to change how the regex is built. Bug: T140240 Change-Id: I014d9b13815d8ae085a6ed7c6df2d62337bb46f7 --- resources/src/jquery/jquery.tablesorter.js | 4 +-- .../jquery/jquery.tablesorter.test.js | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/resources/src/jquery/jquery.tablesorter.js b/resources/src/jquery/jquery.tablesorter.js index 50bfa879d9..62be0d8c4a 100644 --- a/resources/src/jquery/jquery.tablesorter.js +++ b/resources/src/jquery/jquery.tablesorter.js @@ -696,11 +696,11 @@ for ( key in ts.collationTable ) { // Check hasOwn to be safe if ( ts.collationTable.hasOwnProperty( key ) ) { - keys.push( key ); + keys.push( mw.RegExp.escape( key ) ); } } if ( keys.length ) { - ts.collationRegex = new RegExp( '[' + keys.join( '' ) + ']', 'ig' ); + ts.collationRegex = new RegExp( keys.join( '|' ), 'ig' ); } } } diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index b09bb2825b..ca26aaf904 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -81,6 +81,24 @@ [ 'Strasse' ] ], + // Data set "digraph" + digraphWords = [ + [ 'London' ], + [ 'Ljubljana' ], + [ 'Luxembourg' ], + [ 'Njivice' ], + [ 'Norwich' ], + [ 'New York' ] + ], + digraphWordsSorted = [ + [ 'London' ], + [ 'Luxembourg' ], + [ 'Ljubljana' ], + [ 'New York' ], + [ 'Norwich' ], + [ 'Njivice' ] + ], + complexMDYDates = [ [ 'January, 19 2010' ], [ 'April 21 1991' ], @@ -697,6 +715,22 @@ } ); + tableTest( + 'Digraphs with custom collation', + [ 'City' ], + digraphWords, + digraphWordsSorted, + function ( $table ) { + mw.config.set( 'tableSorterCollation', { + lj: 'lzzzz', + nj: 'nzzzz' + } ); + + $table.tablesorter(); + $table.find( '.headerSort:eq(0)' ).click(); + } + ); + QUnit.test( 'Rowspan not exploded on init', 1, function ( assert ) { var $table = tableCreate( header, planets ); -- 2.20.1