Skip to content

Commit 3baa2a0

Browse files
authored
Merge pull request #205 from leonvogt/fix-crash-on-non-http-links
Fix crash on non-HTTP scheme links
2 parents 3725b5b + 011afcb commit 3baa2a0

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

core/src/main/kotlin/dev/hotwire/core/turbo/config/PathConfigurationData.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.hotwire.core.turbo.config
22

33
import com.google.gson.annotations.SerializedName
4+
import java.net.MalformedURLException
45
import java.net.URL
56

67
@ConsistentCopyVisibility
@@ -36,7 +37,11 @@ data class PathConfigurationData internal constructor(
3637
}
3738

3839
private fun path(location: String): String {
39-
val url = URL(location)
40+
val url = try {
41+
URL(location)
42+
} catch (e: MalformedURLException) {
43+
return ""
44+
}
4045

4146
return if (url.query == null) {
4247
url.path

core/src/test/kotlin/dev/hotwire/core/turbo/config/PathConfigurationTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ class PathConfigurationTest : BaseRepositoryTest() {
201201
assertThat(pathConfiguration.properties("$url/new").pullToRefreshEnabled).isFalse
202202
}
203203

204+
@Test
205+
fun unknownSchemeLocationDoesNotThrow() {
206+
assertThat(pathConfiguration.properties("mailto:test@example.com")).isNotNull
207+
assertThat(pathConfiguration.properties("tel:+15551234567")).isNotNull
208+
assertThat(pathConfiguration.properties("sms:+15551234567")).isNotNull
209+
assertThat(pathConfiguration.properties("custom-app://feature")).isNotNull
210+
}
211+
204212
@Test
205213
fun customProperties() {
206214
assertThat((pathConfiguration.properties("$url/custom/tabs").getTabs()?.size)).isEqualTo(1)

0 commit comments

Comments
 (0)