From 9b86d3be8fe75d12261ad76db52b83d0e283861a Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 19 Mar 2023 15:03:23 +0000 Subject: [PATCH] [build] Encode URL parts to escape HTML chars for build-index --- .../src/buildIndex/SnapshotVersions.kt | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ci-release-helper/src/buildIndex/SnapshotVersions.kt b/ci-release-helper/src/buildIndex/SnapshotVersions.kt index b3d3f4c62..da4eedfd0 100644 --- a/ci-release-helper/src/buildIndex/SnapshotVersions.kt +++ b/ci-release-helper/src/buildIndex/SnapshotVersions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -52,13 +52,14 @@ suspend fun HttpClient.getExistingIndex( commitRef: String, ): Index? { // https://build.mirai.mamoe.net/v1/mirai-core/dev/indexes/?commitRef=29121565132bed6e996f3de32faaf49106ae8e39 - val resp = get("https://build.mirai.mamoe.net/v1/$module/$branch/indexes/") { - basicAuth( - System.getenv("mirai.build.index.auth.username"), - System.getenv("mirai.build.index.auth.password") - ) - parameter("commitRef", commitRef) - } + val resp = + get("https://build.mirai.mamoe.net/v1/${module.encodeURLPathPart()}/${branch.encodeURLPathPart()}/indexes/") { + basicAuth( + System.getenv("mirai.build.index.auth.username"), + System.getenv("mirai.build.index.auth.password") + ) + parameter("commitRef", commitRef) + } if (!resp.status.isSuccess()) { val body = runCatching { resp.bodyAsText() }.getOrNull() throw IllegalStateException("Request failed: ${resp.status} $body") @@ -74,7 +75,7 @@ suspend fun HttpClient.createBranch( branch: String, ): Boolean { // https://build.mirai.mamoe.net/v1/mirai-core/dev/indexes/?commitRef=29121565132bed6e996f3de32faaf49106ae8e39 - val resp = put("https://build.mirai.mamoe.net/v1/$module/$branch") { + val resp = put("https://build.mirai.mamoe.net/v1/${module.encodeURLPathPart()}/${branch.encodeURLPathPart()}") { basicAuth( System.getenv("mirai.build.index.auth.username"), System.getenv("mirai.build.index.auth.password") @@ -88,13 +89,14 @@ suspend fun HttpClient.postNextIndex( branch: String, commitRef: String, ): Index { - val resp = post("https://build.mirai.mamoe.net/v1/$module/$branch/indexes/next") { - basicAuth( - System.getenv("mirai.build.index.auth.username"), - System.getenv("mirai.build.index.auth.password") - ) - parameter("commitRef", commitRef) - } + val resp = + post("https://build.mirai.mamoe.net/v1/${module.encodeURLPathPart()}/${branch.encodeURLPathPart()}/indexes/next") { + basicAuth( + System.getenv("mirai.build.index.auth.username"), + System.getenv("mirai.build.index.auth.password") + ) + parameter("commitRef", commitRef) + } if (!resp.status.isSuccess()) { val body = runCatching { resp.bodyAsText() }.getOrNull() throw IllegalStateException("Request failed: ${resp.status} $body")