Skip to content

Commit 5543329

Browse files
committed
fix(demo): normalize bare-domain URLs for consistent behavior
normalizeUrl now appends trailing slash to bare-domain URLs (e.g. https://example.comhttps://example.com/) to match browser normalization behavior. This ensures manual URL entry and programmatic navigation behave consistently across platforms.
1 parent eabd7f3 commit 5543329

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

  • demo-shared/src/commonMain/kotlin/io/github/kdroidfilter/webview/demo

demo-shared/src/commonMain/kotlin/io/github/kdroidfilter/webview/demo/DemoUtils.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ package io.github.kdroidfilter.webview.demo
33
internal fun normalizeUrl(raw: String): String {
44
val trimmed = raw.trim()
55
if (trimmed.isEmpty()) return "about:blank"
6-
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) return trimmed
76
if (trimmed.startsWith("file://")) return trimmed
8-
return "https://$trimmed"
7+
8+
val url = if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
9+
trimmed
10+
} else {
11+
"https://$trimmed"
12+
}
13+
14+
// Add trailing slash for bare-domain URLs (e.g. https://example.com → https://example.com/)
15+
// to match browser normalization behavior
16+
val schemeEnd = url.indexOf("://") + 3
17+
val pathStart = url.indexOf('/', schemeEnd)
18+
if (pathStart == -1 && url.indexOf('?', schemeEnd) == -1 && url.indexOf('#', schemeEnd) == -1) {
19+
return "$url/"
20+
}
21+
return url
922
}
1023

1124
internal fun hostFromUrl(url: String): String? {

0 commit comments

Comments
 (0)