[gnome-maps/wip/mlundblad/osm-location-url-no-qm: 2/2] uris: Accept OSM location URLs without ?
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/osm-location-url-no-qm: 2/2] uris: Accept OSM location URLs without ?
- Date: Mon, 7 Feb 2022 21:36:30 +0000 (UTC)
commit a109d938ff55412744da0341c75888aa29f90bd4
Author: Marcus Lundblad <ml update uu se>
Date: Mon Feb 7 22:07:53 2022 +0100
uris: Accept OSM location URLs without ?
Sometimes shared URLs pointing to a location in OSM
is on the form https://www.openstreetmap.org/#map=...
E.g. encoding the parameters as part of the path
instead of a query.
Accept both variants, and add an additional test case.
src/uris.js | 7 +++++--
tests/urisTest.js | 2 ++
2 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/uris.js b/src/uris.js
index 97ed4c42..6575b222 100644
--- a/src/uris.js
+++ b/src/uris.js
@@ -40,8 +40,11 @@ function parseAsCoordinateURL(url) {
* the # as a work-around
*/
let uri = GLib.Uri.parse(url.replace('#map=', 'map='), GLib.UriFlags.NONE);
- let params = GLib.Uri.parse_params(uri.get_query(), -1, '&',
- GLib.UriParamsFlags.NONE);
+ let query = uri.get_query();
+ let path = uri.get_path();
+ // allow OSM location URLs encoding the location with or without a ?
+ let params = GLib.Uri.parse_params(query ?? path.replace('/', ''), -1,
+ '&', GLib.UriParamsFlags.NONE);
let lat = params.lat;
let lon = params.lon;
diff --git a/tests/urisTest.js b/tests/urisTest.js
index f7991ec8..4c08bfb8 100644
--- a/tests/urisTest.js
+++ b/tests/urisTest.js
@@ -62,6 +62,8 @@ function parseAsCoordinateURLTest() {
URIS.parseAsCoordinateURL('https://www.openstreetmap.org/?lat=39.9882&lon=-78.2409&zoom=14&layers=B000FTF'));
_assertArrayEquals([59.40538, 17.34894, 12],
URIS.parseAsCoordinateURL('https://www.openstreetmap.org/?#map=12/59.40538/17.34894'));
+ _assertArrayEquals([59.3083, 18.0183, 16],
+ URIS.parseAsCoordinateURL('https://www.openstreetmap.org/#map=16/59.3083/18.0183'));
}
function parseMapsURITest() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]