Patch from Bug #28406:
authorMark A. Hershberger <mah@users.mediawiki.org>
Wed, 6 Apr 2011 00:56:22 +0000 (00:56 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Wed, 6 Apr 2011 00:56:22 +0000 (00:56 +0000)
    # the digitClass join versions were inverted: for a maxLength > 1 it should be
      (|||), not []
    # 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.
    # 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.

I didn't include the “non-breaking space is part of \s” bit since I didn't want to mess up browser bug work-arounds

skins/common/wikibits.js

index b862f5c..3f9dc67 100644 (file)
@@ -740,17 +740,16 @@ window.ts_initTransformTable = function() {
                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 @@ window.ts_initTransformTable = function() {
                "^(" +
                        "[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific
                        "|" +
-                       "[-+\u2212]?" + digitClass + "+%?" + // Generic localised
+                       "[-+\u2212]?" + digitClass + "+[\s\xa0]*%?" + // Generic localised
                ")$", "i"
        );
 };