From c22735ce615a1b8d19499bff0a31d1efa8540fe6 Mon Sep 17 00:00:00 2001 From: Mariia Skripchenko <61115099+marychatte@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:12:41 +0200 Subject: [PATCH] Release 2.3.12 (#4088) --- .github/ISSUE_TEMPLATE/config.yml | 2 +- CHANGELOG.md | 13 +++ gradle.properties | 2 +- gradle/libs.versions.toml | 22 ++-- .../src/io/ktor/http/FileContentType.kt | 25 +++- ktor-http/common/src/io/ktor/http/Mimes.kt | 1 + ktor-io/linux/src/CharsetLinux.kt | 6 +- ktor-io/mingwX64/src/CharsetMingw.kt | 6 +- .../src/io/ktor/network/sockets/Sockets.kt | 5 +- .../server/plugins/swagger/SwaggerConfig.kt | 2 +- .../server/plugins/swagger/SwaggerTest.kt | 6 +- .../io/ktor/server/webjars/WebjarsTest.kt | 109 +++++++++--------- .../jvm/test-resources/public/types/file.css | 0 .../jvm/test-resources/public/types/file.js | 0 .../jvm/test-resources/public/types/file.svg | 0 .../jvm/test-resources/public/types/file.xml | 0 .../ktor/server/plugins/StaticContentTest.kt | 21 ++++ .../common/src/io/ktor/events/Events.kt | 6 +- 18 files changed, 141 insertions(+), 85 deletions(-) create mode 100644 ktor-server/ktor-server-tests/jvm/test-resources/public/types/file.css create mode 100644 ktor-server/ktor-server-tests/jvm/test-resources/public/types/file.js create mode 100644 ktor-server/ktor-server-tests/jvm/test-resources/public/types/file.svg create mode 100644 ktor-server/ktor-server-tests/jvm/test-resources/public/types/file.xml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index d20f4045944..b9d13e48440 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,4 +2,4 @@ blank_issues_enabled: false contact_links: - name: Create url: https://youtrack.jetbrains.com/newIssue?project=KTOR - about: Please report any new issue using youtrack + about: Please report any new issues to the JetBrains YouTrack diff --git a/CHANGELOG.md b/CHANGELOG.md index 4550acc90fb..6b6cc4b64d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +# 2.3.12 +> Published 20 June 2024 + +### Bugfixes +* NoSuchMethodError when using coroutines 1.9.0-RC ([KTOR-7054](https://youtrack.jetbrains.com/issue/KTOR-7054)) +* Server: Content-Type header for static js, css and svg resources misses charset ([KTOR-6655](https://youtrack.jetbrains.com/issue/KTOR-6655)) +* Embedded Linux device without iso-8859-1 and UTF-16 cannot use ktor-network ([KTOR-7016](https://youtrack.jetbrains.com/issue/KTOR-7016)) + +### Improvements +* Update netty to 4.1.111.Final ([KTOR-7094](https://youtrack.jetbrains.com/issue/KTOR-7094)) +* Update netty due to CVE-2024-29025 ([KTOR-7014](https://youtrack.jetbrains.com/issue/KTOR-7014)) +* Update dependency on swagger ([KTOR-7019](https://youtrack.jetbrains.com/issue/KTOR-7019)) + # 2.3.11 > Published 8 May 2024 diff --git a/gradle.properties b/gradle.properties index de403c012f2..c5f067187fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ ktor.ide.jvmAndCommonOnly=true kotlin.code.style=official # config -version=2.3.10 +version=2.3.12 # gradle org.gradle.daemon=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d9250b6eefd..92b9e1f7c9b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,16 +7,16 @@ serialization-version = "1.5.1" validator-version = "0.8.0" ktlint-version = "3.15.0" -netty-version = "4.1.106.Final" -netty-tcnative-version = "2.0.62.Final" +netty-version = "4.1.111.Final" +netty-tcnative-version = "2.0.65.Final" -jetty-version = "9.4.53.v20231009" -jetty-jakarta-version = "11.0.20" +jetty-version = "9.4.54.v20240208" +jetty-jakarta-version = "11.0.21" jetty-alpn-api-version = "1.1.3.v20160715" jetty-alpn-boot-version = "8.1.13.v20181017" -jetty-alpn-openjdk8 = "9.4.53.v20231009" +jetty-alpn-openjdk8 = "9.4.54.v20240208" -tomcat-version = "9.0.85" +tomcat-version = "9.0.89" tomcat-jakarta-version = "10.1.18" apache-version = "4.1.5" @@ -30,10 +30,10 @@ gson-version = "2.10.1" jackson-version = "2.16.1" junit-version = "4.13.2" -slf4j-version = "2.0.11" +slf4j-version = "2.0.13" logback-version = "1.3.14" -dropwizard-version = "4.2.25" +dropwizard-version = "4.2.26" micrometer-version = "1.12.4" jansi-version = "2.4.1" @@ -44,8 +44,8 @@ mockk-version = "1.13.5" java-jwt-version = "4.4.0" jwks-rsa-version = "0.22.1" -mustache-version = "0.9.11" -freemarker-version = "2.3.32" +mustache-version = "0.9.13" +freemarker-version = "2.3.33" pebble-version = "3.2.2" velocity-version = "2.3" velocity-tools-version = "3.1" @@ -63,7 +63,7 @@ yamlkt-version = "0.13.0" swagger-codegen-version = "3.0.41" swagger-codegen-generators-version = "1.0.38" -swagger-parser-version = "2.1.19" +swagger-parser-version = "2.1.22" [libraries] kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin-version" } diff --git a/ktor-http/common/src/io/ktor/http/FileContentType.kt b/ktor-http/common/src/io/ktor/http/FileContentType.kt index 1c921d6ab6a..9bb1327ed22 100644 --- a/ktor-http/common/src/io/ktor/http/FileContentType.kt +++ b/ktor-http/common/src/io/ktor/http/FileContentType.kt @@ -65,11 +65,34 @@ private val extensionsByContentType: Map> by lazy { internal fun List.selectDefault(): ContentType { val contentType = firstOrNull() ?: ContentType.Application.OctetStream return when { - contentType.contentType == "text" && contentType.charset() == null -> contentType.withCharset(Charsets.UTF_8) + contentType.match(ContentType.Text.Any) -> contentType.withCharsetUTF8IfNeeded() + contentType.match(ContentType.Image.SVG) -> contentType.withCharsetUTF8IfNeeded() + contentType.matchApplicationTypeWithCharset() -> contentType.withCharsetUTF8IfNeeded() else -> contentType } } +private fun ContentType.matchApplicationTypeWithCharset(): Boolean { + if (!match(ContentType.Application.Any)) return false + + return when { + match(ContentType.Application.Atom) || + match(ContentType.Application.JavaScript) || + match(ContentType.Application.Rss) || + match(ContentType.Application.Xml) || + match(ContentType.Application.Xml_Dtd) + -> true + + else -> false + } +} + +private fun ContentType.withCharsetUTF8IfNeeded(): ContentType { + if (charset() != null) return this + + return withCharset(Charsets.UTF_8) +} + internal fun Sequence>.groupByPairs() = groupBy { it.first } .mapValues { e -> e.value.map { it.second } } diff --git a/ktor-http/common/src/io/ktor/http/Mimes.kt b/ktor-http/common/src/io/ktor/http/Mimes.kt index 0e243d483f1..a5fd21ffd23 100644 --- a/ktor-http/common/src/io/ktor/http/Mimes.kt +++ b/ktor-http/common/src/io/ktor/http/Mimes.kt @@ -428,6 +428,7 @@ private val rawMimes: String .jpgv,video/jpeg .jpm,video/jpm .jps,image/x-jps +.js,text/javascript .js,application/javascript .json,application/json .jut,image/jutvision diff --git a/ktor-io/linux/src/CharsetLinux.kt b/ktor-io/linux/src/CharsetLinux.kt index 9e44fa72c93..0edb99471d3 100644 --- a/ktor-io/linux/src/CharsetLinux.kt +++ b/ktor-io/linux/src/CharsetLinux.kt @@ -10,9 +10,9 @@ import platform.iconv.* import platform.posix.* public actual object Charsets { - public actual val UTF_8: Charset = CharsetIconv("UTF-8") - public actual val ISO_8859_1: Charset = CharsetIconv("ISO-8859-1") - internal val UTF_16: Charset = CharsetIconv(platformUtf16) + public actual val UTF_8: Charset by lazy { CharsetIconv("UTF-8") } + public actual val ISO_8859_1: Charset by lazy { CharsetIconv("ISO-8859-1") } + internal val UTF_16: Charset by lazy { CharsetIconv(platformUtf16) } } internal actual fun findCharset(name: String): Charset { diff --git a/ktor-io/mingwX64/src/CharsetMingw.kt b/ktor-io/mingwX64/src/CharsetMingw.kt index 804e846f4c9..1ed8179d951 100644 --- a/ktor-io/mingwX64/src/CharsetMingw.kt +++ b/ktor-io/mingwX64/src/CharsetMingw.kt @@ -10,9 +10,9 @@ import platform.iconv.* import platform.posix.* public actual object Charsets { - public actual val UTF_8: Charset = CharsetIconv("UTF-8") - public actual val ISO_8859_1: Charset = CharsetIconv("ISO-8859-1") - internal val UTF_16: Charset = CharsetIconv(platformUtf16) + public actual val UTF_8: Charset by lazy { CharsetIconv("UTF-8") } + public actual val ISO_8859_1: Charset by lazy { CharsetIconv("ISO-8859-1") } + internal val UTF_16: Charset by lazy { CharsetIconv(platformUtf16) } } private class CharsetIconv(name: String) : Charset(name) { diff --git a/ktor-network/jvmAndNix/src/io/ktor/network/sockets/Sockets.kt b/ktor-network/jvmAndNix/src/io/ktor/network/sockets/Sockets.kt index 53b68a6ee37..38fb9bc028c 100644 --- a/ktor-network/jvmAndNix/src/io/ktor/network/sockets/Sockets.kt +++ b/ktor-network/jvmAndNix/src/io/ktor/network/sockets/Sockets.kt @@ -66,8 +66,11 @@ public interface ABoundSocket { */ public interface Acceptable : ASocket { /** - * accepts socket connection or suspends if none yet available. + * Suspends until a connection is available and returns it or throws if something + * goes wrong. + * * @return accepted socket + * @throws IOException */ public suspend fun accept(): S } diff --git a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt index e39c926f6b0..a69ced719d3 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt @@ -13,7 +13,7 @@ public class SwaggerConfig { /** * Specifies a Swagger UI version to use. */ - public var version: String = "4.14.0" + public var version: String = "5.17.12" /** * Specifies a URL for a custom CSS applied to a Swagger UI. diff --git a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt index 16a200d577a..3eb6696298e 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt @@ -24,12 +24,12 @@ class SwaggerTest { Swagger UI - +
- - + +