Skip to content

feat(drivers/alias): support filename escaping - #2868

Open
qbisi wants to merge 2 commits into
OpenListTeam:mainfrom
qbisi:feat/alias-filename-escape
Open

feat(drivers/alias): support filename escaping#2868
qbisi wants to merge 2 commits into
OpenListTeam:mainfrom
qbisi:feat/alias-filename-escape

Conversation

@qbisi

@qbisi qbisi commented Jul 29, 2026

Copy link
Copy Markdown

该 feat 的一个直接 benefit 是用于 189cloud 文件名中 ' 和 U+4E73 字符的可逆替换:前者会被 189cloud 替换为不一致的 \',后者会导致文件无法下载;替换后字符分别变为 _x0027__x4E73__xHHHH_ 是一种在 XML、数据库以及电子表格解析中用于表示非法或无效字符的转义编码格式,其中 HHHH 代表该字符的四位十六进制 Unicode / UCS-2 编码。该格式能够兼容大部分网盘,是一种成熟的替换方案。

由于新增了 filename_escapefilename_escape_charsfilename_auto_rename 三个配置项,前端需要同步增加翻译。

Summary / 摘要

  • 为 Alias 存储增加默认关闭的 filename_escapefilename_auto_rename 开关,以及按行配置待转义字符串的 filename_escape_chars

  • 开启文件名转义后,在 Alias 读写边界匹配配置字符串,并仅将匹配字符串的首字符转换为 _xHHHH_ UTF-16 代码单元格式;同时保护原本存在的 _xHHHH_ 字面量。

  • 读取列表时保留后端真实路径,仅向用户展示还原后的名称;创建目录、重命名、上传和 URL 上传时向后端传递转义后的名称。

  • 开启 filename_auto_rename 后,Alias 在列出目录时自动将命中的后端既有文件或目录重命名为转义名称;迁移失败时保留原路径并继续列出目录。

  • 直接获取文件时兼容已存在的未转义文件名。

  • 改动仅限 Alias 驱动,不修改公共驱动接口或 internal 文件系统流程。

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。

  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。

  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Related Issues / 关联 Issue

Relates to #2792

Testing / 测试

  • go test ./...
  • go test ./drivers/alias ./internal/op ./internal/fs
  • git diff --check
  • Manual test / 手动测试

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING。
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 此 PR 已是 ready-for-review 状态,尚未额外请求维护者或 code owner 审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • Codex

Usage scope / 使用范围:

  • Code generation / 代码生成

  • Refactoring / 重构

  • Tests / 测试

  • Review assistance / 审查辅助

  • I have reviewed and validated all AI-assisted content included in this PR.
    / 已审查并验证此 PR 中包含的 AI 辅助内容。

  • I have ensured that all AI-assisted commits include Co-Authored-By attribution.
    / AI 辅助提交已包含 Co-authored-by 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

@qbisi
qbisi marked this pull request as ready for review July 29, 2026 21:39
qbisi and others added 2 commits July 30, 2026 08:16
- 增加默认关闭的文件名转义配置
- 在 Alias 读写边界转换 UTF-16 转义名称
- 保留后端真实路径并兼容未转义的已有文件

Co-authored-by: Codex <267193182+codex@users.noreply.github.com>
- add an opt-in setting to rename matching backend objects during directory listing
- preserve original paths when automatic renaming fails

Co-authored-by: Codex <267193182+codex@users.noreply.github.com>

Copilot AI 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.

Pull request overview

This PR adds optional filename escaping/auto-rename behavior to the Alias driver to improve compatibility with backends that reject or mangle certain characters (e.g., ' and U+4E73), by encoding configured “match strings” into an _xHHHH_ (UTF-16 code unit) representation at read/write boundaries while presenting decoded names to users.

Changes:

  • Add new Alias config knobs: filename_escape, filename_escape_chars, and filename_auto_rename.
  • Encode names on write paths (mkdir/rename/upload/put-url) and decode names on read paths (get/list), while preserving backend raw paths for operations.
  • Optionally auto-rename matching existing backend objects to the escaped form during directory listing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
drivers/alias/meta.go Adds three new configuration fields controlling filename escaping and optional auto-rename.
drivers/alias/driver.go Implements filename encode/decode utilities and integrates them into Get, List, and write operations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread drivers/alias/driver.go
Comment on lines +167 to 171
for _, root := range roots {
objs = append(objs, &tempObj{model.Object{
Path: stdpath.Join(d, sub),
Path: stdpath.Join(root, d.escapeFilenamePath(sub)),
}})
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

escape是一对一,unescape应该设计成多对一解析替换所有出现的_xHHHH_,期望的get逻辑应该匹配所有unescape后match的文件,对多个unescape后相同的文件操作时可以继承alias对于多个后端操作时的相同逻辑。

Comment thread drivers/alias/driver.go
Comment on lines +606 to +610
func (d *Alias) escapeFilename(name string, encode bool) string {
if !d.FilenameEscape {
return name
}
var protected, characters []string
@xrgzs xrgzs changed the title feat(alias): support filename escaping feat(drivers/alias): support filename escaping Jul 31, 2026
@xrgzs xrgzs added enhancement Module: Driver Driver-Related Issue/PR labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Module: Driver Driver-Related Issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants