Skip to content

Commit

Permalink
Fix parsing of lowercase S/W directions
Browse files Browse the repository at this point in the history
We were matching the direction case-insensitively in the regex, but then
comparing it case-sensitively afterwards, so that lowercase S/W
coordinates would not be parsed as S/W and would instead eventually end
up being interpreted as unsigned (i. e. N/E). To fix this, it’s
sufficient to check if the regex matched that part of the pattern at
all or fell back to the empty alternative branch.

Credit for investigating the bug goes to Wikidata user Nikki [1] on
Phabricator [2].

This is a backport for the 3.0.x line, cherry-picked from 5443722.

[1]: https://www.wikidata.org/wiki/User:Nikki
[2]: https://phabricator.wikimedia.org/T173026#4465312

Bug: T173026
  • Loading branch information
lucaswerkmeister committed Aug 1, 2018
1 parent 1735bdd commit 49cd65d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ for the [Maps](https://github.com/JeroenDeDauw/Maps) and

## Release notes

### 3.0.1 (2018-08-01)

* Fixed parsing of coordinates with lowercase S/W directions

### 3.0.0 (2018-03-20)

* Removed `DATAVALUES_GEO_VERSION` constant
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/LatLongParserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected function resolveDirection( $coordinateSegment ) {
$matches
);

if ( $matches[1] === $direction || $matches[3] === $direction ) {
if ( $matches[1] !== '' || $matches[3] !== '' ) {
$coordinateSegment = $matches[2];

if ( in_array( $direction, [ $s, $w ] ) ) {
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Parsers/LatLongParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public function validInputProvider() {
'0° 0.3\' S 0° 0.3\' W' => [ -0.005, -0.005 ],
'-55° 30′ -37° 30′' => [ -55.5, -37.5 ],
'S 0° 0.3\' W 0° 0.3\'' => [ -0.005, -0.005 ],

// case insensitive
'55 s, 37.6176330 w' => [ -55, -37.6176330 ],
'5.5s,37w ' => [ -5.5, -37 ],
'5.5s 37w ' => [ -5.5, -37 ],
's5.5 w37 ' => [ -5.5, -37 ],
'5.5S 37w ' => [ -5.5, -37 ],
'5.5s 37W ' => [ -5.5, -37 ],
];

foreach ( $valid as $value => $expected ) {
Expand Down

0 comments on commit 49cd65d

Please sign in to comment.