Skip to content

Commit 6cd7dcd

Browse files
committed
feat(demand): 修复 Demand 的一个小问题
1 parent f43427b commit 6cd7dcd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

common-legacy-api/src/main/kotlin/taboolib/common5/Demand.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ package taboolib.common5
3939
* @since 2020/11/22 2:51 下午
4040
*/
4141
@Suppress("ReplaceSubstringWithDropLast", "ReplaceSubstringWithTake")
42-
class Demand(val source: String) {
42+
class Demand(source: String) {
43+
44+
val source = source.trim()
4345

4446
lateinit var namespace: String
4547

@@ -112,6 +114,9 @@ class Demand(val source: String) {
112114
setKey: (String) -> Unit,
113115
setState: (ParseState) -> Unit
114116
) {
117+
if (arg.isEmpty()) {
118+
return
119+
}
115120
val ch = arg[0]
116121
when {
117122
// 处理标签

common-legacy-api/src/test/kotlin/TestDemand.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ class DemandTest {
226226
// 性能断言:平均每次解析应该少于1ms(可以根据实际情况调整)
227227
assertTrue(avgTime < 1.0, "平均解析时间过长: ${avgTime}ms")
228228
}
229+
230+
@Test
231+
fun testSpace() {
232+
Demand(" command arg1 arg2 ")
233+
Demand(" command arg1 arg2 -key1 value1 -key2 \"value with spaces\" --tag1 --tag2 ")
234+
}
229235
}
230236

231237
/**

0 commit comments

Comments
 (0)