Skip to content

feat(system): 支持 Windows 上的前往文件夹指令#496

Merged
lzx8589561 merged 2 commits into
ZToolsCenter:mainfrom
guopenghui:feature/open-folder-on-windows
May 17, 2026
Merged

feat(system): 支持 Windows 上的前往文件夹指令#496
lzx8589561 merged 2 commits into
ZToolsCenter:mainfrom
guopenghui:feature/open-folder-on-windows

Conversation

@guopenghui

Copy link
Copy Markdown
Contributor

变成内容

扩充【前往文件夹】指令的正则表达式,支持 window 文件路径

动机

使【前往文件夹】指令在 Windows 平台上正常工作

截图

image

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the system plugin's folder path regex to support Windows-style paths (drive letters and backslashes) and introduces a new test suite to verify path matching across different operating systems. Feedback focuses on refining the Windows regex to exclude invalid characters like asterisks and pipes, and improving type safety in the test code by avoiding the 'any' type.

{
"type": "regex",
"match": "/^(?:~?\\/[^/\\n\\r\\f\\v]+)+\\/?$/",
"match": "/^(?:(?:~?\\/[^/\\n\\r\\f\\v]+)+\\/?|[A-Za-z]:\\\\(?:[^\\\\\\n\\r\\f\\v]+\\\\?)*)$/",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

当前的正则表达式对 Windows 路径的验证不够严格。Windows 文件名或文件夹名中不允许包含 \ / : * ? " < > | 等字符。您当前的实现 [^\\\n\r\f\v] 只排除了反斜杠和部分空白符,可能会匹配到如 C:\Users\* 这样的无效路径。建议收紧该部分的字符集,以确保只匹配有效的路径。

Suggested change
"match": "/^(?:(?:~?\\/[^/\\n\\r\\f\\v]+)+\\/?|[A-Za-z]:\\\\(?:[^\\\\\\n\\r\\f\\v]+\\\\?)*)$/",
"match": "/^(?:(?:~?\\/[^/\\n\\r\\f\\v]+)+\\/??|[A-Za-z]:\\\\(?:[^\\\\/:*?\"<>|\\n\\r\\f\\v]+\\\\?)*)$/",

Comment on lines +14 to +15
const feature = pluginConfig.features.find((item: any) => item.code === 'open-folder')
const regexCmd = feature?.cmds?.find((item: any) => item.type === 'regex')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的类型安全性和可读性,建议在测试代码中也避免使用 any 类型。您可以为 find 方法中的回调函数参数 item 提供更具体的类型,而不是直接使用 any,这样 TypeScript 就能正确推断后续变量的类型,并提供更好的类型检查。

Suggested change
const feature = pluginConfig.features.find((item: any) => item.code === 'open-folder')
const regexCmd = feature?.cmds?.find((item: any) => item.type === 'regex')
const feature = pluginConfig.features.find((item: { code: string; cmds: any[] }) => item.code === 'open-folder')
const regexCmd = feature?.cmds?.find((item: { type: string }) => item.type === 'regex')

@lzx8589561 lzx8589561 merged commit 16f9042 into ZToolsCenter:main May 17, 2026
@guopenghui guopenghui deleted the feature/open-folder-on-windows branch May 17, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants