MaxSem has submitted this change and it was merged.
Change subject: Detect fractional numbers where they shouldn't be in coordinates
......................................................................
Detect fractional numbers where they shouldn't be in coordinates
Change-Id: Idc3a4480ec20fb5b4551654c9350648351162126
---
M GeoData.body.php
M tests/ParseCoordTest.php
2 files changed, 12 insertions(+), 0 deletions(-)
Approvals:
awjrichards: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/GeoData.body.php b/GeoData.body.php
index f5c1fb2..79e5804 100644
--- a/GeoData.body.php
+++ b/GeoData.body.php
@@ -96,8 +96,13 @@
$count = count( $parts );
$multiplier = 1;
$value = 0;
+ $alreadyFractional = false;
for ( $i = 0; $i < $count; $i++ ) {
+ // 20° 15.5' 20" is wrong
+ if ( $alreadyFractional ) {
+ return false;
+ }
$part = $parts[$i];
if ( $i > 0 && $i == $count - 1 ) {
$suffix = self::parseSuffix( $part, $coordInfo
);
@@ -119,6 +124,7 @@
|| $part > $max ) {
return false;
}
+ $alreadyFractional = $part != intval( $part );
$value += $part * $multiplier * GeoDataMath::sign(
$value );
$multiplier /= 60;
}
diff --git a/tests/ParseCoordTest.php b/tests/ParseCoordTest.php
index 007e89e..9efc087 100644
--- a/tests/ParseCoordTest.php
+++ b/tests/ParseCoordTest.php
@@ -58,6 +58,12 @@
array( array( 1, 2, 3, 'N', 'E' ), false ),
array( array( 1, 2, 3, 'N', 1, 'E' ), false ),
array( array( 1, 2, 3, 'N', 1, 2, 'E' ), false ),
+ // Fractional numbers inconsistency
+ array( array( 1, 2.1, 3, 1, 2, 3 ), false ),
+ array( array( 1, 2.1, 3.2, 1, 2, 3 ), false ),
+ array( array( 1.00000001, 2.1, 3.2, 1, 2, 3 ), false ),
+ array( array( 1.00000001, 2.1, 3, 1, 2, 3 ), false ),
+ array( array( 1.00000001, 2, 3, 1, 2, 3 ), false ),
// coordinate validation (Earth)
array( array( -90, 180 ), new Coord( -90, 180 ) ),
array( array( 90.0000001, -180.00000001 ), false ),
--
To view, visit https://gerrit.wikimedia.org/r/51124
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idc3a4480ec20fb5b4551654c9350648351162126
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: awjrichards <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits