From e1c56be8708dd7143cc403277fcfd93989e157b8 Mon Sep 17 00:00:00 2001 From: madd Date: Sun, 22 Apr 2018 15:52:03 +0200 Subject: [PATCH] jquery.tablesorter: References ignored in sortkey. Text in elements with class='reference' excluded for sorting. Bug: T29745 Change-Id: If3969c00cbb7a74362fe85f4cad361da488526d5 --- resources/src/jquery/jquery.tablesorter.js | 6 +++- .../jquery/jquery.tablesorter.test.js | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/resources/src/jquery/jquery.tablesorter.js b/resources/src/jquery/jquery.tablesorter.js index 8aa22a856c..e9d5a917a0 100644 --- a/resources/src/jquery/jquery.tablesorter.js +++ b/resources/src/jquery/jquery.tablesorter.js @@ -79,7 +79,11 @@ } return $.makeArray( node.childNodes ).map( function ( elem ) { if ( elem.nodeType === Node.ELEMENT_NODE ) { - return getElementSortKey( elem ); + if ( $( elem ).hasClass( 'reference' ) ) { + return null; + } else { + return getElementSortKey( elem ); + } } return $.text( elem ); } ).join( '' ); diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index 23ef26f6f6..74caf5ca3a 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -1494,5 +1494,33 @@ 'detectParserForColumn() detect parser.id "number" for second column' ); } ); + QUnit.test( 'T29745 - References ignored in sortkey', function ( assert ) { + var $table, parsers; + $table = $( + '' + + '' + + '' + + '' + + '
A
10
2[1]
' + ); + $table.tablesorter(); + $table.find( '.headerSort:eq(0)' ).click(); + + assert.deepEqual( + tableExtract( $table ), + [ + [ '2[1]' ], + [ '10' ] + ], + 'References ignored in sortkey' + ); + + parsers = $table.data( 'tablesorter' ).config.parsers; + assert.equal( + parsers[ 0 ].id, + 'number', + 'detectParserForColumn() detect parser.id "number"' + ); + } ); }( jQuery, mediaWiki ) ); -- 2.20.1