mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Merge pull request #7340 from hayaksi1/fix/7289-custom-map-style-url
Do not append the application MapTiler key to a custom map style url
This commit is contained in:
+5
-8
@@ -29,14 +29,11 @@ internal class MapTilerTileServerStyleUriBuilder(
|
||||
customMapStyleUrl: String?,
|
||||
darkMode: Boolean,
|
||||
): String {
|
||||
return buildString {
|
||||
if (customMapStyleUrl.isNullOrBlank()) {
|
||||
val mapId = if (darkMode) darkMapId else lightMapId
|
||||
append("$baseUrl/$mapId/style.json")
|
||||
} else {
|
||||
append(customMapStyleUrl)
|
||||
}
|
||||
append("?key=$apiKey")
|
||||
return if (customMapStyleUrl.isNullOrBlank()) {
|
||||
val mapId = if (darkMode) darkMapId else lightMapId
|
||||
"$baseUrl/$mapId/style.json?key=$apiKey"
|
||||
} else {
|
||||
customMapStyleUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+32
-2
@@ -46,7 +46,7 @@ class MapTilerTileServerStyleUriBuilderTest {
|
||||
customMapStyleUrl = "https://custom.url/style.json",
|
||||
darkMode = false,
|
||||
)
|
||||
).isEqualTo("https://custom.url/style.json?key=anApiKey")
|
||||
).isEqualTo("https://custom.url/style.json")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,6 +56,36 @@ class MapTilerTileServerStyleUriBuilderTest {
|
||||
customMapStyleUrl = "https://custom.url/style.json",
|
||||
darkMode = true,
|
||||
)
|
||||
).isEqualTo("https://custom.url/style.json?key=anApiKey")
|
||||
).isEqualTo("https://custom.url/style.json")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `custom map uri with its own api key is not altered`() {
|
||||
assertThat(
|
||||
builder.build(
|
||||
customMapStyleUrl = "https://api.maptiler.com/maps/streets-v2/style.json?key=anOperatorKey",
|
||||
darkMode = false,
|
||||
)
|
||||
).isEqualTo("https://api.maptiler.com/maps/streets-v2/style.json?key=anOperatorKey")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `custom map uri with an existing query is not altered`() {
|
||||
assertThat(
|
||||
builder.build(
|
||||
customMapStyleUrl = "https://self.hosted/style.json?foo=bar",
|
||||
darkMode = true,
|
||||
)
|
||||
).isEqualTo("https://self.hosted/style.json?foo=bar")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `blank custom map uri falls back to the built-in style`() {
|
||||
assertThat(
|
||||
builder.build(
|
||||
customMapStyleUrl = " ",
|
||||
darkMode = false,
|
||||
)
|
||||
).isEqualTo("https://base.url/aLightMapId/style.json?key=anApiKey")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user