feat(system): 支持 Windows 上的前往文件夹指令#496
Conversation
There was a problem hiding this comment.
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]+\\\\?)*)$/", |
There was a problem hiding this comment.
当前的正则表达式对 Windows 路径的验证不够严格。Windows 文件名或文件夹名中不允许包含 \ / : * ? " < > | 等字符。您当前的实现 [^\\\n\r\f\v] 只排除了反斜杠和部分空白符,可能会匹配到如 C:\Users\* 这样的无效路径。建议收紧该部分的字符集,以确保只匹配有效的路径。
| "match": "/^(?:(?:~?\\/[^/\\n\\r\\f\\v]+)+\\/?|[A-Za-z]:\\\\(?:[^\\\\\\n\\r\\f\\v]+\\\\?)*)$/", | |
| "match": "/^(?:(?:~?\\/[^/\\n\\r\\f\\v]+)+\\/??|[A-Za-z]:\\\\(?:[^\\\\/:*?\"<>|\\n\\r\\f\\v]+\\\\?)*)$/", |
| const feature = pluginConfig.features.find((item: any) => item.code === 'open-folder') | ||
| const regexCmd = feature?.cmds?.find((item: any) => item.type === 'regex') |
There was a problem hiding this comment.
为了提高代码的类型安全性和可读性,建议在测试代码中也避免使用 any 类型。您可以为 find 方法中的回调函数参数 item 提供更具体的类型,而不是直接使用 any,这样 TypeScript 就能正确推断后续变量的类型,并提供更好的类型检查。
| 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') |
变成内容
扩充【前往文件夹】指令的正则表达式,支持 window 文件路径
动机
使【前往文件夹】指令在 Windows 平台上正常工作
截图