Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1903. Added code to parse the url if valid else return null #3139

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ktor-http/common/src/io/ktor/http/Url.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ public class Url internal constructor(
return urlString.hashCode()
}

public companion object
public companion object {
public fun parse(urlString: String): Url? {
return Url(urlString)
}
}
}

@Suppress("UNUSED_PARAMETER")
Expand Down
12 changes: 12 additions & 0 deletions ktor-http/common/test/io/ktor/tests/http/UrlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,16 @@ class UrlTest {
val url = Url(urlString)
assertEquals(urlString, "$url")
}

@Test
fun testUrlWithGivenString() {
val validUrl = "https://localhost:8080/validUrl"
assertNotNull(Url.parse(validUrl), "Invalid Url")
}

@Test
fun testInvalidUrlReturnsNull() {
val bogusUrl = "bogus"
assertNull(Url.parse(bogusUrl))
}
}