From debe5baae470e3733733a7f525daf07858c67ed1 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Tue, 24 Nov 2020 12:52:03 +0800 Subject: [PATCH] Improve PluginDependency.parseFromString --- .../src/plugin/description/PluginDependency.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/mirai-console/src/plugin/description/PluginDependency.kt b/backend/mirai-console/src/plugin/description/PluginDependency.kt index a575e8bb4..a5645a63a 100644 --- a/backend/mirai-console/src/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/plugin/description/PluginDependency.kt @@ -66,7 +66,7 @@ public data class PluginDependency @JvmOverloads constructor( public override fun toString(): String = buildString { append(id) versionRequirement?.let { - append(":") + append(':') append(it) } if (isOptional) { @@ -83,10 +83,14 @@ public data class PluginDependency @JvmOverloads constructor( public fun parseFromString(string: String): PluginDependency { require(string.isNotEmpty()) { "string is empty." } val optional = string.endsWith('?') - val (id, version) = string.removeSuffix("?").let { - it.substringBeforeLast(':') to it.substringAfterLast(':', "") + val (id, version) = string.removeSuffix("?").let { rule -> + if (rule.contains(':')) { + rule.substringBeforeLast(':') to rule.substringAfterLast(':') + } else { + rule to null + } } - return PluginDependency(id, version.takeIf(String::isNotBlank), optional) + return PluginDependency(id, version, optional) } }