ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
13k stars 1.06k forks source link

URLParser doesn't handle all scheme/protocols correctly #1614

Closed vdesmet93 closed 4 years ago

vdesmet93 commented 4 years ago

Ktor Version and Engine Used (client or server and name) Tested with Ktor Client Common 1.3.70-eap-42, but bug is present in current stable version as well.

Describe the bug The URLParser (used by the URLBuilder) does not support schemes with numbers, plus ("+"), period ("."), or hyphen ("-") characters. This is not according to the RFC 3986 specification: https://tools.ietf.org/html/rfc3986#page-17

The findScheme function only handles schems with letters and when no scheme can be parsed it will default to http as scheme and localhost as host.

To Reproduce Execute

val urlBuilder = URLBuilder(urlString = "test-scheme123://ktor.io/index.html")
println("Test URL: ${urlBuilder.buildString()}")

This will print

Test URL: http://localhost/test-scheme123://ktor.io/index.html

Expected behavior The URLParser should correctly handle these types of URL schemes, and in this case it should print the initial URL that was passed to the URLBuilder.

dmitrievanthony commented 4 years ago

Hi @vdesmet93,

Thanks for reporting. I fixed this bug in #1635, so the fix will be included in the next release 1.3.2.