Index: trunk/extensions/ParserFunctions/convertTests.txt |
— | — | @@ -19,10 +19,10 @@ |
20 | 20 | *{{#convert: 10.0E2 km | m }} |
21 | 21 | *{{#convert: 10.0E2.5 km | m }} |
22 | 22 | !! result |
23 | | -<ul><li>0.01 kilometers |
24 | | -</li><li>0.01 kilometers |
| 23 | +<ul><li>0.01 kilometers |
| 24 | +</li><li>0.01kilometers |
25 | 25 | </li><li>10,000 meters |
26 | | -</li><li>10,000- meters |
| 26 | +</li><li>10,000-meters |
27 | 27 | </li><li>1,000,000 meters |
28 | 28 | </li><li>100 meters |
29 | 29 | </li><li>1,000,000 meters |
— | — | @@ -201,8 +201,8 @@ |
202 | 202 | *{{#convert: 10 pa | mmhg | #language = en-gb }} |
203 | 203 | *{{#convert: 10 pa | mmhg | #language = /../evil/attack }} |
204 | 204 | !! result |
205 | | -<ul><li>0.01 kilometres |
206 | | -</li><li>0.01 kilometres |
| 205 | +<ul><li>0.01 kilometres |
| 206 | +</li><li>0.01kilometres |
207 | 207 | </li><li>10,000 metres |
208 | 208 | </li><li>0.1 milimetres of mercury |
209 | 209 | </li><li>0.1 milimeters of mercury |
Index: trunk/extensions/ParserFunctions/Convert.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | class ConvertParser { |
18 | 18 | |
19 | 19 | # A regex which matches the body of the string and the source unit separately |
20 | | - const UNITS_REGEX = '/^(.+?)\s*([a-z]+\^?\d?(?:\/\w+\^?\d?)*)$/i'; |
| 20 | + const UNITS_REGEX = '/^(.+?)([a-z]+\^?\d?(?:\/\w+\^?\d?)*)$/i'; |
21 | 21 | |
22 | 22 | # A regex which matches a number |
23 | 23 | const NUM_REGEX = '/\b((?:\+|\-|−|\x2212)?(\d+(?:\.\d+)?)(?:E(?:\+|\-|−|\x2212)?\d+)?)\b/i'; |
— | — | @@ -151,6 +151,10 @@ |
152 | 152 | # Get the source unit, if not already set. This throws ConvertError on failure |
153 | 153 | if ( !$this->sourceUnit instanceof ConvertUnit ){ |
154 | 154 | $this->deduceSourceUnit( $string ); |
| 155 | + } else { |
| 156 | + # The string has no unit on the end, so it's been trimmed to the end of the |
| 157 | + # last digit, meaning the unit specified by #sourceunit won't have any space |
| 158 | + $string .= ' '; |
155 | 159 | } |
156 | 160 | |
157 | 161 | # Use the default unit (SI usually) |
— | — | @@ -190,10 +194,10 @@ |
191 | 195 | $string = preg_replace_callback( |
192 | 196 | self::NUM_REGEX, |
193 | 197 | array( $this, 'convert' ), |
194 | | - trim( preg_replace( self::UNITS_REGEX, '$1', $string ) ) |
| 198 | + ltrim( preg_replace( self::UNITS_REGEX, '$1', $string ) ) |
195 | 199 | ); |
196 | 200 | if( $this->raw ){ |
197 | | - return $string; |
| 201 | + return trim( $string ); |
198 | 202 | } else { |
199 | 203 | $unit = $this->targetUnit->getText( |
200 | 204 | $this->lastValue, |
— | — | @@ -201,7 +205,7 @@ |
202 | 206 | $this->abbreviate, |
203 | 207 | $this->language |
204 | 208 | ); |
205 | | - return "$string $unit"; |
| 209 | + return $string . $unit; |
206 | 210 | } |
207 | 211 | } |
208 | 212 | |
— | — | @@ -737,7 +741,7 @@ |
738 | 742 | $msgText = "$msgText/$msg2Text"; |
739 | 743 | } |
740 | 744 | |
741 | | - return $msgText; |
| 745 | + return trim( $msgText ); |
742 | 746 | } |
743 | 747 | |
744 | 748 | protected function getTextFromMessage( $key, $number, $link, $abbreviate, $language ){ |