Skip to content

Commit 720a36f

Browse files
committed
fix: use accessible language rather than technical RFC terminology
1 parent 82a8590 commit 720a36f

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/main/kotlin/com/coder/toolbox/util/URLExtensions.kt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@ fun String.validateStrictWebUrl(): WebUrlValidationResult = try {
1212
val uri = URI(this)
1313

1414
when {
15-
uri.isOpaque -> Invalid("$this is opaque, instead of hierarchical")
16-
!uri.isAbsolute -> Invalid("$this is relative, it must be absolute")
17-
uri.scheme?.lowercase() !in setOf("http", "https") ->
18-
Invalid("Scheme for $this must be either http or https")
15+
uri.isOpaque -> Invalid(
16+
"The URL \"$this\" is invalid because it is not in the standard format. " +
17+
"Please enter a full web address like \"https://example.com\""
18+
)
1919

20+
!uri.isAbsolute -> Invalid(
21+
"The URL \"$this\" is missing a scheme (like https://). " +
22+
"Please enter a full web address like \"https://example.com\""
23+
)
24+
uri.scheme?.lowercase() !in setOf("http", "https") ->
25+
Invalid(
26+
"The URL \"$this\" must start with http:// or https://, not \"${uri.scheme}\""
27+
)
2028
uri.authority.isNullOrBlank() ->
21-
Invalid("$this does not have a hostname")
22-
29+
Invalid(
30+
"The URL \"$this\" does not include a valid website name. " +
31+
"Please enter a full web address like \"https://example.com\""
32+
)
2333
else -> Valid
2434
}
25-
} catch (e: Exception) {
26-
Invalid(e.message ?: "$this could not be parsed as a URI reference")
35+
} catch (_: Exception) {
36+
Invalid(
37+
"The input \"$this\" is not a valid web address. " +
38+
"Please enter a full web address like \"https://example.com\""
39+
)
2740
}
2841

2942
fun URL.withPath(path: String): URL = URL(

src/test/kotlin/com/coder/toolbox/util/URLExtensionsTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal class URLExtensionsTest {
7878
val url = "/bin/coder-linux-amd64"
7979
val result = url.validateStrictWebUrl()
8080
assertEquals(
81-
WebUrlValidationResult.Invalid("$url is relative, it must be absolute"),
81+
WebUrlValidationResult.Invalid("The URL \"/bin/coder-linux-amd64\" is missing a scheme (like https://). Please enter a full web address like \"https://example.com\""),
8282
result
8383
)
8484
}
@@ -88,7 +88,7 @@ internal class URLExtensionsTest {
8888
val url = "mailto:user@coder.com"
8989
val result = url.validateStrictWebUrl()
9090
assertEquals(
91-
WebUrlValidationResult.Invalid("$url is opaque, instead of hierarchical"),
91+
WebUrlValidationResult.Invalid("The URL \"mailto:user@coder.com\" is invalid because it is not in the standard format. Please enter a full web address like \"https://example.com\""),
9292
result
9393
)
9494
}
@@ -98,7 +98,7 @@ internal class URLExtensionsTest {
9898
val url = "ftp://coder.com"
9999
val result = url.validateStrictWebUrl()
100100
assertEquals(
101-
WebUrlValidationResult.Invalid("Scheme for $url must be either http or https"),
101+
WebUrlValidationResult.Invalid("The URL \"ftp://coder.com\" must start with http:// or https://, not \"ftp\""),
102102
result
103103
)
104104
}
@@ -108,7 +108,7 @@ internal class URLExtensionsTest {
108108
val url = "http:///bin/coder-linux-amd64"
109109
val result = url.validateStrictWebUrl()
110110
assertEquals(
111-
WebUrlValidationResult.Invalid("$url does not have a hostname"),
111+
WebUrlValidationResult.Invalid("The URL \"http:///bin/coder-linux-amd64\" does not include a valid website name. Please enter a full web address like \"https://example.com\""),
112112
result
113113
)
114114
}
@@ -118,7 +118,7 @@ internal class URLExtensionsTest {
118118
val url = "http://[invalid-uri]"
119119
val result = url.validateStrictWebUrl()
120120
assertEquals(
121-
WebUrlValidationResult.Invalid("Malformed IPv6 address at index 8: $url"),
121+
WebUrlValidationResult.Invalid("The input \"http://[invalid-uri]\" is not a valid web address. Please enter a full web address like \"https://example.com\""),
122122
result
123123
)
124124
}
@@ -128,7 +128,7 @@ internal class URLExtensionsTest {
128128
val url = "http//coder.com"
129129
val result = url.validateStrictWebUrl()
130130
assertEquals(
131-
WebUrlValidationResult.Invalid("http//coder.com is relative, it must be absolute"),
131+
WebUrlValidationResult.Invalid("The URL \"http//coder.com\" is missing a scheme (like https://). Please enter a full web address like \"https://example.com\""),
132132
result
133133
)
134134
}
@@ -138,7 +138,7 @@ internal class URLExtensionsTest {
138138
val url = "http:coder.com"
139139
val result = url.validateStrictWebUrl()
140140
assertEquals(
141-
WebUrlValidationResult.Invalid("http:coder.com is opaque, instead of hierarchical"),
141+
WebUrlValidationResult.Invalid("The URL \"http:coder.com\" is invalid because it is not in the standard format. Please enter a full web address like \"https://example.com\""),
142142
result
143143
)
144144
}
@@ -148,7 +148,7 @@ internal class URLExtensionsTest {
148148
val url = "https:/coder.com"
149149
val result = url.validateStrictWebUrl()
150150
assertEquals(
151-
WebUrlValidationResult.Invalid("https:/coder.com does not have a hostname"),
151+
WebUrlValidationResult.Invalid("The URL \"https:/coder.com\" does not include a valid website name. Please enter a full web address like \"https://example.com\""),
152152
result
153153
)
154154
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy