Skip to content

Commit

Permalink
fix(common): add URL decoding of georel parameter (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal authored Nov 22, 2023
1 parent 144c156 commit 1a05c16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun parseGeoQueryParameters(
requestParams: Map<String, String>,
contexts: List<String>
): Either<APIException, GeoQuery?> = 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1a05c16

Please sign in to comment.