r67423 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67422‎ | r67423 | r67424 >
Date:06:35, 6 June 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added extra sanitasion method to coordinate parser class
Modified paths:
  • /trunk/extensions/Maps/Includes/Maps_CoordinateParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Includes/Maps_CoordinateParser.php
@@ -179,6 +179,8 @@
180180 * @return string The normalized version of the provided coordinates.
181181 */
182182 protected static function normalizeCoordinates( $coordinates ) {
 183+ $coordinates = self::removeInvalidChars( $coordinates );
 184+
183185 $coordinates = str_replace( ' ', '', $coordinates );
184186
185187 $coordinates = str_replace( array( '°', '°' ), Maps_GEO_DEG, $coordinates );
@@ -190,6 +192,27 @@
191193 }
192194
193195 /**
 196+ * Returns a string with control characters and characters with ascii values above 126 removed.
 197+ *
 198+ * @param string $string Yeah, it's a string, seriously!
 199+ *
 200+ * @return string
 201+ */
 202+ protected static function removeInvalidChars( $string ) {
 203+ $filtered = array();
 204+
 205+ foreach ( str_split( $string ) as $character ) {
 206+ $asciiValue = ord( $character );
 207+
 208+ if ( $asciiValue > 31 and $asciiValue < 127 ) {
 209+ $filtered[] = $character;
 210+ }
 211+ }
 212+
 213+ return implode( '', $filtered );
 214+ }
 215+
 216+ /**
194217 * Formats a single non-directional float coordinate in the given notation.
195218 *
196219 * @param string $coordinate The coordinate to be formatted.

Status & tagging log