Conversation
Summary of ChangesHello @YueerMoe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在解决 Windows 用户在更新应用程序时遇到的“系统找不到路径”错误。通过调整生成更新批处理脚本中路径的引用方式,确保 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This PR aims to fix path escaping issues in the Windows update script by changing cmd.exe path references from " to "". However, the proposed fix using ""{temp_dir}"" introduces a command injection vulnerability when paths contain & and breaks support for spaces; a safer quoting method is recommended. The PR also includes unit tests, which is a good practice, but there appears to be a typo in a new test case that might cause it to fail. Additionally, please ensure exe_name and other path components are validated to prevent path traversal and further command injection risks in other parts of the batch script construction.
src-tauri/src/services/update.rs
Outdated
|
|
||
| echo 清理临时文件... | ||
| start "" /min cmd /c "timeout /t 3 /nobreak >nul & if exist \"{temp_dir}\" rd /s /q \"{temp_dir}\"" | ||
| start "" /min cmd /c "timeout /t 3 /nobreak >nul & if exist ""{temp_dir}"" rd /s /q ""{temp_dir}""" |
There was a problem hiding this comment.
The use of double-double quotes ""{temp_dir}"" inside a cmd /c command string is vulnerable to command injection and will fail for paths containing spaces. In cmd.exe, "" is interpreted as two separate double quotes (an empty quoted string), which leaves the subsequent path unquoted. If the path contains an ampersand (&), it will be treated as a command separator, allowing for arbitrary command execution. For example, if temp_dir is C:\Users\A&B\Temp, the command will attempt to execute B\Temp. Additionally, this syntax causes a syntax error when the path contains spaces (e.g., C:\Program Files). The correct way to quote a path for cmd /c in a batch file is to use single double quotes "{temp_dir}", ensuring no backslashes are used for escaping as they are treated literally by cmd.exe.
| start "" /min cmd /c "timeout /t 3 /nobreak >nul & if exist ""{temp_dir}"" rd /s /q ""{temp_dir}""" | |
| start "" /min cmd /c "timeout /t 3 /nobreak >nul & if exist "{temp_dir}" rd /s /q "{temp_dir}"" |
src-tauri/src/services/update.rs
Outdated
| assert!(content.contains( | ||
| r#"if exist ""C:\Temp\endfield-cat-update"" rd /s /q ""C:\Temp\endfield-cat-update""""# | ||
| )); |
There was a problem hiding this comment.
这里的断言字符串似乎不正确,可能导致测试无法通过。
build_updater_batch 函数生成的批处理命令中,清理临时目录的命令部分在格式化后会是 ... if exist ""C:\Temp..."" rd /s /q ""C:\Temp...""",其中路径参数后有三个双引号。
然而,当前的测试断言 content.contains(...) 检查的是一个以四个双引号结尾的字符串,这与实际生成的内容不符。
为了在测试中正确表示一个包含三个双引号的字符串,可以考虑使用 r##"..."## 形式的原始字符串字面量。
| assert!(content.contains( | |
| r#"if exist ""C:\Temp\endfield-cat-update"" rd /s /q ""C:\Temp\endfield-cat-update""""# | |
| )); | |
| assert!(content.contains( | |
| r##"if exist ""C:\Temp\endfield-cat-update"" rd /s /q ""C:\Temp\endfield-cat-update"""#"## | |
| )); |
将更新脚本的 cmd 引号转义修复从 dev 合入 preview。
说明:此前该修复曾直接落在 preview(已 revert),现在按流程 dev -> preview -> master 重新走一遍。