fix(task): 启动参数含引号或空格时不再把引号一起传给进程 - #866
Open
beichen24a1 wants to merge 1 commit into
Open
beichen24a1 wants to merge 1 commit into
beichen24a1 wants to merge 1 commit into
Conversation
split_args 用 shlex.split(posix=False) 拆分,引号会被留在词元里:`--flag "a b"` 拆成 `['"a b"']`,交给 CreateProcess 后游戏收到的是一个带引号的参数,多半当无效参数丢掉。 而配置校验用的 ArgumentValidator 走 posix 模式,界面上看着一切正常、保存也成功,于是这类 参数只在运行时静默失效——「界面里还在、跑起来不生效」。 改成 posix 解析但关掉转义处理(shlex.shlex + escape=""):引号只用于分组,Windows 路径里 的反斜杠原样保留,不会像裸 posix 模式那样被当转义符吃掉。 验证(用 python.exe 当假游戏,把 MAS 的真实启动链路 split_args → ProcessManager. open_process → 进程 argv 跑穿,不启动真实游戏客户端): - `-Res=1920x1080` 等无引号参数:进程收到的 argv 与修复前逐字相同 - `--path "C:\Program Files\Game\game.exe"`:修复前进程收到带引号的整个串,修复后收到 `C:\Program Files\Game\game.exe`(反斜杠保留) - `--flag "a b"`:修复前 `'"a b"'`,修复后 `a b`;`--name 'my game'` 同理 - ruff check / ruff format --check app/task/proxy_helpers.py:通过 - python -m pytest tests/task -q:17 passed - python -m pytest tests --collect-only -q:308 collected,exit 0
There was a problem hiding this comment.
Sorry @beichen24a1, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 2 days and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.
审查者指南(在较小的 PR 中折叠)审查者指南本 PR 修复启动参数运行时解析与界面校验语义不一致的问题:通过 POSIX 分组规则并禁用转义处理,让带空格或引号的参数以去除包裹引号、保留 Windows 反斜杠的形式传递给进程,同时记录该行为修复。验证覆盖真实启动链路及现有任务测试,但边界验证未作为测试文件提交。 修正后的任务参数解析时序图sequenceDiagram
participant Task as Task
participant split_args as split_args
participant ProcessManager as ProcessManager
participant Game as TargetProcess
Task->>split_args: split_args(raw)
split_args->>split_args: shlex.shlex(value, posix=True)
split_args->>split_args: lexer.escape = ""
split_args-->>Task: list[str] without grouping quotes
Task->>ProcessManager: open_process(args)
ProcessManager->>Game: CreateProcess(args)
Game-->>ProcessManager: argv preserves spaces and backslashes
文件级变更
提示和命令与 Sourcery 互动
自定义你的使用体验访问你的 仪表板 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's Guide本 PR 修复启动参数运行时解析与界面校验语义不一致的问题:通过 POSIX 分组规则并禁用转义处理,让带空格或引号的参数以去除包裹引号、保留 Windows 反斜杠的形式传递给进程,同时记录该行为修复。验证覆盖真实启动链路及现有任务测试,但边界验证未作为测试文件提交。 Sequence diagram for corrected task argument parsingsequenceDiagram
participant Task as Task
participant split_args as split_args
participant ProcessManager as ProcessManager
participant Game as TargetProcess
Task->>split_args: split_args(raw)
split_args->>split_args: shlex.shlex(value, posix=True)
split_args->>split_args: lexer.escape = ""
split_args-->>Task: list[str] without grouping quotes
Task->>ProcessManager: open_process(args)
ProcessManager->>Game: CreateProcess(args)
Game-->>ProcessManager: argv preserves spaces and backslashes
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
现象:用户在脚本里配的启动参数(例如
--path "C:\Program Files\Game\game.exe")在界面上看着正常、保存也成功,运行时却不生效。split_args()用shlex.split(..., posix=False),引号会被留在词元里——--flag "a b"拆成['"a b"'],交给 CreateProcess 后游戏收到的是一个带引号的参数,多半当无效参数丢掉ArgumentValidator走 posix 模式(引号只用于分组),所以界面校验一切正常,这类参数只在运行时静默失效shlex.shlex+escape = ""):引号只用于分组,Windows 路径里的反斜杠原样保留,不会像裸 posix 模式那样被当转义符吃掉验证
用
python.exe当假游戏,把 MAS 的真实启动链路(split_args→ProcessManager.open_process→ 进程实际argv)整条跑穿,不启动任何真实游戏客户端:-Res=1920x1080["-Res=1920x1080"]["-Res=1920x1080"](逐字不变)-Res=1920x1080 --windowed["-Res=1920x1080", "--windowed"]--path "C:\Program Files\Game\game.exe"["--path", "\"C:\\Program Files\\Game\\game.exe\""]← 带引号["--path", "C:\\Program Files\\Game\\game.exe"]✅--flag "a b" --end['--flag', '"a b"', '--end']← 带引号['--flag', 'a b', '--end']✅--name 'my game' -v["--name", "'my game'", "-v"]← 带引号["--name", "my game", "-v"]✅其余检查:
ruff check/ruff format --check app/task/proxy_helpers.py:通过python -m pytest tests/task -q:17 passedpython -m pytest tests --collect-only -q:308 collected,exit 0说明
Sourcery 摘要
修复任务启动参数解析问题,确保带引号的值能够正确分组,同时不会将引号字符传递给启动的进程。
错误修复:
功能增强:
日常维护:
Original summary in English
Summary by Sourcery
Fix task startup argument parsing so quoted values are grouped correctly without passing quote characters to launched processes.
Bug Fixes:
Enhancements:
Chores: