Page MenuHomePhabricator

some wikibits.js fixes for sortable tables
Closed, ResolvedPublic

Description

Author: a.d.bergi

Description:
proposed patch

I've done 4 fixes for the sorttable script:

  1. the digitClass join versions were inverted: for a maxLength > 1 it should be (|||), not []
  2. the regexp escape for digits in the ts_number_transform_table was a bit, er, strange. Although it worked, I think my version is more common.
  3. the non breaking space \xa0 is included in the whitespace shortcut \s (or is there a browser bug?), so I've changed [\xa0\s] to \s
  4. most important: As recommended in http://en.wikipedia.org/wiki/Percent_sign, there may be some whitespaces between the number and the "%". See also Bug 15422 for that, I'm not sure wheter it's included there.

Version: 1.17.x
Severity: normal

attachment bug sortable.patch ignored as obsolete

Details

Reference
bz28406

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:31 PM
bzimport set Reference to bz28406.

Can you make a .diff of the patch, so it's easier for others to review and apply?

More info: http://www.mediawiki.org/wiki/Subversion#Making_a_diff

a.d.bergi wrote:

proposed patch

MIME-type misdetection. Bugzilla-bug?

Attached:

Comment on attachment 8371
proposed patch

Index: wikibits.js

  • wikibits.js (Revision 83609)

+++ wikibits.js (Arbeitskopie)
@@ -626,7 +626,7 @@

	for ( var i = rowStart; i < table.rows.length; i++ ) {
		if ( table.rows[i].cells.length > column ) {
			itm = ts_getInnerText(table.rows[i].cells[column]);
  • itm = itm.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, '');

+ itm = itm.replace(/^\s+/, '').replace(/\s+$/, '');

			if ( itm != '' ) {
				break;
			}

@@ -661,7 +661,7 @@

				keyText = ''; 
			}
			var oldIndex = ( reverse ? -j : j );
  • var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, '') );

+ var preprocessed = preprocessor( keyText.replace(/^\s+/, '').replace(/\s+$/, '') );

			newRows[newRows.length] = new Array( row, preprocessed, oldIndex );
		} else {

@@ -740,17 +740,16 @@

		for ( var digit in ts_number_transform_table ) {
			// Escape regex metacharacters
			digits.push(
  • digit.replace( /[\\\\$\*\+\?\.\(\)\|\{\}\[\]\-]/,
  • function( s ) { return '\\' + s; } )

+ digit.replace( /([{}()|.?*+^$\[\]\\-])/g, "\\$1" )

			);
			if ( digit.length > maxDigitLength ) {
				maxDigitLength = digit.length;
			}
		}
		if ( maxDigitLength > 1 ) {
  • var digitClass = '[' + digits.join( '', digits ) + ']';

+ var digitClass = '(' + digits.join( '|' ) + ')';

		} else {
  • var digitClass = '(' + digits.join( '|', digits ) + ')';

+ var digitClass = '[' + digits.join( '' ) + ']';

		}
	}

@@ -760,7 +759,7 @@

		"^(" +
			"[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific
			"|" +
  • "[-+\u2212]?" + digitClass + "+%?" + // Generic localised

+ "[-+\u2212]?" + digitClass + "+\s*%?" + // Generic localised

		")$", "i"
	);

};

a.d.bergi wrote:

proposed patch

Could you please add the [\xa0\s]-regex to tablesorter.js? r86088 made my patch obsolete.

Attached:

a.d.bergi wrote:

Sorry, I meant the whitespace(s) between the digits and the percentage sign, see the attached patch. The trim method doesn't handle these.

Bergi, DieBuche,

This patch has been marked FIXME in order to get some tests written for it. (See r85497)

Could you write the tests for it? Bergi, If you write the tests I'll commit them and we'll see about getting you commit privs.

per CR on r85497 the code was rewrite. Closing this bug as fixed.