Skip to content

Commit

Permalink
🐛 fix shlex error not catched
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Jan 30, 2025
1 parent 5b280b0 commit d63b438
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions nonebot/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,21 @@ async def __call__(
if cmd not in self.cmds or msg is None:
return False

state[SHELL_ARGV] = list(
chain.from_iterable(
shlex.split(str(seg)) if cast(MessageSegment, seg).is_text() else (seg,)
for seg in msg
try:
state[SHELL_ARGV] = list(
chain.from_iterable(
shlex.split(str(seg))
if cast(MessageSegment, seg).is_text()
else (seg,)
for seg in msg
)
)
)
except Exception as e:
# shlex may raise value error when syntax error
state[SHELL_ARGS] = ParserExit(status=2, message=str(e))
# we need to set SHELL_ARGV to empty list to avoid key error
state[SHELL_ARGV] = []
return True

if self.parser:
t = parser_message.set("")
Expand Down

0 comments on commit d63b438

Please sign in to comment.