Skip to content

fix(Python): pass UTF-8 byte length for log dir option#1310

Open
Windsland52 wants to merge 2 commits into
mainfrom
fix/logdirpath
Open

fix(Python): pass UTF-8 byte length for log dir option#1310
Windsland52 wants to merge 2 commits into
mainfrom
fix/logdirpath

Conversation

@Windsland52
Copy link
Copy Markdown
Member

@Windsland52 Windsland52 commented May 6, 2026

Tasker.set_log_dir encoded the path as UTF-8 but passed the character count to MaaGlobalSetOption. Non-ASCII paths were truncated before native path conversion on Windows, which could surface as an uncaught C++ filesystem exception.

Use the encoded byte length and cover set_log_dir with a non-ASCII path in the binding test.

Summary by Sourcery

修复 Python Tasker 日志目录配置,以正确处理 UTF-8 路径,并在测试中为包含非 ASCII 字符的日志目录路径补充覆盖。

Bug 修复:

  • 通过使用 UTF-8 字节长度而不是字符数来修正传递给 MaaGlobalSetOption 的日志目录选项长度,避免非 ASCII 路径被截断。

测试:

  • 扩展 Python 绑定测试,以验证 Tasker.set_log_dir 在 Windows 风格路径中使用包含非 ASCII 字符的日志目录路径时能够正常工作。
Original summary in English

Summary by Sourcery

Fix Python Tasker log directory configuration to correctly handle UTF-8 paths and add coverage for non-ASCII log directory paths in tests.

Bug Fixes:

  • Correct the length passed to MaaGlobalSetOption for the log directory option by using the UTF-8 byte length instead of the character count to avoid truncation of non-ASCII paths.

Tests:

  • Extend Python binding tests to verify Tasker.set_log_dir works with a non-ASCII log directory path on Windows-like paths.

Tasker.set_log_dir encoded the path as UTF-8 but passed the character
count to MaaGlobalSetOption. Non-ASCII paths were truncated before native
path conversion on Windows, which could surface as an uncaught C++
filesystem exception.

Use the encoded byte length and cover set_log_dir with a non-ASCII path
in the binding test.
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里提供了一些整体性的反馈:

  • set_log_dir 中,建议显式使用 'utf-8' 进行编码(例如 str(path).encode('utf-8')),并将变量命名为 encoded_path_bytes 或类似名称,以明确传递给 MaaGlobalSetOption 的长度是字节长度,而不是字符数量。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
-`set_log_dir` 中,建议显式使用 `'utf-8'` 进行编码(例如 `str(path).encode('utf-8')`),并将变量命名为 `encoded_path_bytes` 或类似名称,以明确传递给 `MaaGlobalSetOption` 的长度是字节长度,而不是字符数量。

Sourcery 对开源项目是免费的——如果你喜欢我们的评审,请考虑帮忙分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • In set_log_dir, consider explicitly encoding with 'utf-8' (e.g., str(path).encode('utf-8')) and naming the variable encoded_path_bytes or similar to make it clear the length passed to MaaGlobalSetOption is a byte length and not a character count.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `set_log_dir`, consider explicitly encoding with `'utf-8'` (e.g., `str(path).encode('utf-8')`) and naming the variable `encoded_path_bytes` or similar to make it clear the length passed to `MaaGlobalSetOption` is a byte length and not a character count.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Windsland52
Copy link
Copy Markdown
Member Author

@MistEO review

Copy link
Copy Markdown
Member

@MistEO MistEO left a comment

Choose a reason for hiding this comment

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

🤖 非 ASCII 路径这个坑修得对,测试也带了,LGTM

@Windsland52
Copy link
Copy Markdown
Member Author

MaaXYZ/MaaUtils#16 合并

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