Explorar el Código

[build] Encode URL parts to escape HTML chars for build-index

Him188 hace 3 años
padre
commit
9b86d3be8f
Se han modificado 1 ficheros con 18 adiciones y 16 borrados
  1. 18 16
      ci-release-helper/src/buildIndex/SnapshotVersions.kt

+ 18 - 16
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")