koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.53k stars 246 forks source link

Bug: `strictOptions: true` 的指令中,以 `-` 开头的文本参数未贪婪匹配 #1473

Closed DGCK81LNN closed 2 weeks ago

DGCK81LNN commented 4 weeks ago

Describe the bug

对于启用 strictOptions 的指令,当文本参数以 - 开头时,其值于第一个空格处被截断。

Steps to reproduce

import { inspect } from "node:util"
// ...
ctx
  .command("test <text:text>", { strictOptions: true })
  .action((_, ...args) => h.text(inspect(args)))

test 123 456 789

['123 456 789']

test -123 456 789

['-123', '456', '789']

Expected behavior

仍然保持贪婪匹配的行为。

Screenshots

No response

Versions

Additional context

No response

DGCK81LNN commented 2 weeks ago

https://github.com/koishijs/koishi/blob/d06e1e9b2ad1d7ae7e31efc7f11249b1133d9450/packages/core/src/command/parser.ts#L396-L399

这里仅检测了 token 是否以 - 开头,没有在 strictOptions 启用的情况下判断其是否是有效的选项。