From 1a05c164567a0c970663c4d09df7c3e00794e6f7 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Wed, 22 Nov 2023 06:31:08 +0100 Subject: [PATCH] fix(common): add URL decoding of georel parameter (#1046) --- .../egm/stellio/shared/util/GeoQueryUtils.kt | 2 +- .../stellio/shared/util/GeoQueryUtilsTests.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/shared/src/main/kotlin/com/egm/stellio/shared/util/GeoQueryUtils.kt b/shared/src/main/kotlin/com/egm/stellio/shared/util/GeoQueryUtils.kt index f1775fbd4..dbf6b1268 100644 --- a/shared/src/main/kotlin/com/egm/stellio/shared/util/GeoQueryUtils.kt +++ b/shared/src/main/kotlin/com/egm/stellio/shared/util/GeoQueryUtils.kt @@ -44,7 +44,7 @@ fun parseGeoQueryParameters( requestParams: Map, contexts: List ): Either = either { - val georel = requestParams[GEO_QUERY_PARAM_GEOREL]?.also { + val georel = requestParams[GEO_QUERY_PARAM_GEOREL]?.decode()?.also { checkGeorelParam(it).bind() } val geometry = requestParams[GEO_QUERY_PARAM_GEOMETRY]?.let { diff --git a/shared/src/test/kotlin/com/egm/stellio/shared/util/GeoQueryUtilsTests.kt b/shared/src/test/kotlin/com/egm/stellio/shared/util/GeoQueryUtilsTests.kt index bb00fe3b2..68b743eea 100644 --- a/shared/src/test/kotlin/com/egm/stellio/shared/util/GeoQueryUtilsTests.kt +++ b/shared/src/test/kotlin/com/egm/stellio/shared/util/GeoQueryUtilsTests.kt @@ -33,6 +33,24 @@ class GeoQueryUtilsTests { assertEquals(geoQuery, geoQueryParams) } + @Test + fun `it should parse URL encoded geo query parameters`() = runTest { + val requestParams = gimmeFullParamsMap( + georel = "near%3BmaxDistance%3D%3D1500" + ).plus("coordinates" to "[57.5522%2C%20-20.3484]") + val geoQueryParams = + parseGeoQueryParameters(requestParams, NGSILD_CORE_CONTEXT).shouldSucceedAndResult() + + val geoQuery = GeoQuery( + georel = "near;maxDistance==1500", + geometry = GeometryType.POINT, + coordinates = "[57.5522, -20.3484]", + wktCoordinates = geoJsonToWkt(GeometryType.POINT, "[57.5522, -20.3484]").getOrNull()!!, + geoproperty = NGSILD_LOCATION_PROPERTY + ) + assertEquals(geoQuery, geoQueryParams) + } + @Test fun `it should parse geo query parameters with geoproperty operation space`() = runTest { val requestParams = gimmeFullParamsMap("operationSpace")