Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/OsmApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OsmApiTest extends TestCase
public function test_url_to_api() {
$this->assertFalse(url_to_api(''));
$this->assertFalse(url_to_api('abc'));
$this->assertFalse(url_to_api(','));

$this->assertEquals(url_to_api('/api/0.6/node/123'), 'https://api.openstreetmap.org/api/0.6/node/123');

Expand All @@ -31,6 +32,14 @@ public function test_url_to_api() {
);

$this->assertEquals(url_to_api('15/12.34/56.78'), 'https://api.openstreetmap.org/api/0.6/map?bbox=56.77970,12.33970,56.78030,12.34030');

$this->assertEquals(
url_to_api(',n12,,,n13,'),
[
'https://api.openstreetmap.org/api/0.6/node/12',
'https://api.openstreetmap.org/api/0.6/node/13'
]
);
}


Expand Down
3 changes: 3 additions & 0 deletions www/osmapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ function renumber_created( $data, $olddata = false ) {
// Checks that $url is to OSM API, converts if otherwise
// Returns false if it cannot be converted
function url_to_api( $url ) {
# Remove all commas from start, end and any duplicate commas
$url = trim(preg_replace('/,+/', ',', $url), ',');

# API calls
if( preg_match('#/api/0.6/((?:node|way|relation|changeset)/\\d+(?:/[0-9a-z]+)?)$#', $url, $m) )
return OSM_API_URL.$m[1];
Expand Down
Loading