Index: trunk/extensions/ParserFunctions/convertTests.txt |
— | — | @@ -198,14 +198,30 @@ |
199 | 199 | *{{#convert: 10 m | km | #language=en-gb }} |
200 | 200 | *{{#convert: 10m | km | #language = en-gb }} |
201 | 201 | *{{#convert: 10 km | m |#language=en-gb}} |
202 | | -*{{#convert: 10 pa | mmhg | #language = en-gb }} |
203 | | -*{{#convert: 10 pa | mmhg | #language = /../evil/attack }} |
| 202 | +*{{#convert: 10 Pa | mmHg | #language = en-gb }} |
204 | 203 | !! result |
205 | 204 | <ul><li>0.01 kilometres |
206 | 205 | </li><li>0.01kilometres |
207 | 206 | </li><li>10,000 metres |
208 | 207 | </li><li>0.1 milimetres of mercury |
| 208 | +</li></ul> |
| 209 | + |
| 210 | +!! end |
| 211 | + |
| 212 | +!! test |
| 213 | +Case sensitivity |
| 214 | +!! input |
| 215 | +*{{#convert: 10 mm | m }} |
| 216 | +*{{#convert: 10 Mm | m }} |
| 217 | +*{{#convert: 10 km | Mm }} |
| 218 | +*{{#convert: 10 Pa | mmHg }} |
| 219 | +*{{#convert: 10 pa | mmHg }} |
| 220 | +!! result |
| 221 | +<ul><li>0.01 meters |
| 222 | +</li><li>10,000,000 meters |
| 223 | +</li><li>0.01 megameters |
209 | 224 | </li><li>0.1 milimeters of mercury |
| 225 | +</li><li><strong class="error">Error: unknown unit "pa"</strong> |
210 | 226 | </li></ul> |
211 | 227 | |
212 | 228 | !! end |
Index: trunk/extensions/ParserFunctions/Convert.php |
— | — | @@ -472,14 +472,14 @@ |
473 | 473 | protected static $units = array( |
474 | 474 | ConvertDimension::DIM_LENGTH => array( |
475 | 475 | 'gigametre' => array( 1000000000, 'Gm' ), |
476 | | - 'megametre' => array( 1000000, '(?:(?-i)Mm)' ), # Case-sensitivity is forced |
| 476 | + 'megametre' => array( 1000000, 'Mm' ), # Case-sensitivity is forced |
477 | 477 | 'kilometre' => array( 1000, 'km' ), |
478 | 478 | 'hectometre' => array( 100, 'hm' ), |
479 | 479 | 'decametre' => array( 10, 'dam' ), |
480 | 480 | 'metre' => array( 1, 'm' ), |
481 | 481 | 'decimetre' => array( 0.1, 'dm' ), |
482 | 482 | 'centimetre' => array( 0.01, 'cm' ), |
483 | | - 'millimetre' => array( 0.001, '(?:(?-i)mm)' ), # Case-sensitivity is forced |
| 483 | + 'millimetre' => array( 0.001, 'mm' ), # Case-sensitivity is forced |
484 | 484 | 'micrometre' => array( 0.0001, '\x03BCm|\x00B5m|um' ), # There are two similar mu characters |
485 | 485 | 'nanometre' => array( 0.0000001, 'nm' ), |
486 | 486 | 'angstrom' => array( 0.00000001, '\x00C5' ), |
— | — | @@ -495,8 +495,8 @@ |
496 | 496 | 'inch' => array( 0.0254, 'inch|inches|in' ), |
497 | 497 | |
498 | 498 | 'nauticalmile' => array( 1852, 'nauticalmiles?|nmi' ), |
499 | | - 'nauticalmileuk' => array( 1853.184, 'oldUKnmi|Brnmi|admi' ), |
500 | | - 'nauticalmileus' => array( 1853.24496, 'oldUSnmi' ), |
| 499 | + 'nauticalmileuk' => array( 1853.184, 'old[Uu][Kk]nmi|[Bb]rnmi|admi' ), |
| 500 | + 'nauticalmileus' => array( 1853.24496, 'old[Uu][Ss]nmi' ), |
501 | 501 | |
502 | 502 | 'gigaparsec' => array( 3.0856775813057E25, 'gigaparsecs?|Gpc' ), |
503 | 503 | 'megaparsec' => array( 3.0856775813057E22, 'megaparsecs?|Mpc' ), |
— | — | @@ -506,7 +506,7 @@ |
507 | 507 | 'mrgalightyear' => array( 9.4607304725808E21, 'megalightyears?|Mly' ), |
508 | 508 | 'kilolightyear' => array( 9.4607304725808E18, 'kilolightyears?|kly' ), |
509 | 509 | 'lightyear' => array( 9.4607304725808E15, 'lightyears?|ly' ), |
510 | | - 'astronomicalunit' => array( 149597870700, 'astronomicalunits?|AU' ), |
| 510 | + 'astronomicalunit' => array( 149597870700, 'astronomicalunits?|AU|au' ), |
511 | 511 | ), |
512 | 512 | |
513 | 513 | ConvertDimension::DIM_AREA => array( |
— | — | @@ -575,11 +575,11 @@ |
576 | 576 | |
577 | 577 | ConvertDimension::DIM_PRESSURE => array( |
578 | 578 | 'gigapascal' => array( 1000000000, 'GPa' ), |
579 | | - 'megapascal' => array( 1000000, '(?:(?-i)M[Pp]a)' ), # Case-sensitivity is forced |
| 579 | + 'megapascal' => array( 1000000, 'MPa' ), # Case-sensitivity is forced |
580 | 580 | 'kilopascal' => array( 1000, 'kPa' ), |
581 | 581 | 'hectopascal' => array( 100, 'hPa' ), |
582 | 582 | 'pascal' => array( 1, 'Pa' ), |
583 | | - 'millipascal' => array( 0.001, '(?:(?-i)m[Pp]a)' ), # Case-sensitivity is forced |
| 583 | + 'millipascal' => array( 0.001, 'mPa' ), # Case-sensitivity is forced |
584 | 584 | |
585 | 585 | 'bar' => array( 100000, 'bar' ), |
586 | 586 | 'decibar' => array( 10000, 'dbar' ), |
— | — | @@ -609,7 +609,7 @@ |
610 | 610 | |
611 | 611 | # An array of preprocessing conversions to apply to units |
612 | 612 | protected static $unitConversions = array( |
613 | | - '/^mph$/ui' => 'mi/h', |
| 613 | + '/^mph$/u' => 'mi/h', |
614 | 614 | ); |
615 | 615 | |
616 | 616 | # Map of UNIT => DIMENSION, created on construct |
— | — | @@ -664,7 +664,7 @@ |
665 | 665 | # Single unit |
666 | 666 | foreach( self::$units as $dimension => $units ){ |
667 | 667 | foreach( $units as $unit => $data ){ |
668 | | - if( $rawUnit == $unit || preg_match( "/^({$data[1]})$/ui", $parts[0] ) ){ |
| 668 | + if( $rawUnit == $unit || preg_match( "/^({$data[1]})$/u", $parts[0] ) ){ |
669 | 669 | $this->dimension = new ConvertDimension( self::$dimensionMap[$unit] ); |
670 | 670 | $this->conversion = self::$units[$this->dimension->value][$unit][0]; |
671 | 671 | $this->regex = $data[1]; |