fix: support empty string literals in textfx #63
Reference in New Issue
Block a user
No description provided.
Delete Branch "pi-agent/konabot:fix/textfx-empty-string"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
User description
问题
echo ""和echo ''会报错「请在 echo 后面添加需要输出的文本」,无法正确处理空字符串字面量。根本原因
tokenizer 的
flush_word()只在buf非空时才添加 token,导致空引号""或''不会生成空字符串 token。修复方案
flush_word()添加force参数""和''都会生成空字符串 token测试
test_echo_empty_string测试用例echo ""和echo ''都能正确输出空字符串PR Type
Bug fix, Tests
Description
修复空字符串字面量
""/''解析问题echo遵循 Unix 语义,不再读取 stdin移除 tokenizer 中冗余的全角空格检查
新增空字符串 echo 测试用例
Diagram Walkthrough
File Walkthrough
base.py
移除 tokenizer 中冗余的空格判断条件konabot/plugins/handle_text/base.py
" "检查,仅保留c.isspace()判断unix_handlers.py
echo 对齐 Unix 语义,不再读 stdinkonabot/plugins/handle_text/handlers/unix_handlers.py
istream读取 stdin 的逻辑echo无参数时输出空行,对齐 Unix 语义test_textfx_shell.py
新增 echo 空字符串测试用例tests/test_textfx_shell.py
test_echo_empty_string测试用例echo ""和echo ''均输出空字符串且返回码为 0PR Reviewer Guide 🔍
(Review updated until commit
7e8fa45f36)Here are some key observations to aid the review process:
行为变更
echo移除了对istream的处理逻辑。之前在管道中istream不为None时会将其与args拼接输出,现在完全忽略了istream。这可能导致管道场景(如cat file | echo)的行为发生破坏性变更,需要确认是否有其他调用方依赖了旧的 stdin 读取行为。缺少关键改动
PR 描述中提到为
flush_word()添加了force参数,并在引号闭合时强制 flush 空 buffer,但 diff 中未展示这部分改动。仅移除了全角空格检查,需要确认 tokenizer 中引号闭合处理和flush_word(force=True)的逻辑是否确实存在且正确实现。PR Code Suggestions ✨
Explore these optional code suggestions:
澄清冗余的空白字符检查
这行代码中
c in " "的字符串包含两个全角空格(或看起来相同的空白字符),与c.isspace()的检查存在大量重叠。请确认该字符串确实包含预期的特殊空白字符(如全角空格
\u3000),否则这个条件分支是冗余的。如果意图是匹配特定的 Unicode空白字符,建议使用显式的 Unicode 转义来提高可读性和正确性。
konabot/plugins/handle_text/base.py [192]
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies that
c in " "contains characters that likely overlap withc.isspace(), and recommends using explicit Unicode escapes like\u3000for clarity. This is a reasonable readability improvement. However, the actual content of the string" "is ambiguous from the diff alone — it could contain full-width spaces or other special whitespace. The suggestion is valid but speculative about the exact characters, and the impact is moderate since it's a readability/maintainability concern rather than a bug.Persistent review updated to latest commit
7e8fa45f36PR Code Suggestions ✨
Explore these optional code suggestions:
澄清冗余的空白字符检查
这行代码中
c in " "的字符串包含两个全角空格(或看起来相同的空白字符),与c.isspace()的检查存在大量重叠。请确认该字符串确实包含预期的特殊空白字符(如全角空格
\u3000),否则这个条件分支是冗余的。如果意图是匹配特定的 Unicode空白字符,建议使用显式的 Unicode 转义来提高可读性和正确性。
konabot/plugins/handle_text/base.py [192]
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies that
c in " "contains characters that likely overlap withc.isspace(), and recommends using explicit Unicode escapes like\u3000for clarity. This is a reasonable readability improvement. However, the actual content of the string" "is ambiguous from the diff alone — it could contain full-width spaces or other special whitespace. The suggestion is valid but speculative about the exact characters, and the impact is moderate since it's a readability/maintainability concern rather than a bug.Persistent review updated to latest commit
7e8fa45f36PR Code Suggestions ✨
No code suggestions found for the PR.