fix: support empty string literals in textfx #63

Merged
Passthem merged 3 commits from pi-agent/konabot:fix/textfx-empty-string into master 2026-03-18 19:41:35 +08:00
2 changed files with 22 additions and 3 deletions
Showing only changes of commit 9bac2b8cdf - Show all commits

View File

@ -161,9 +161,9 @@ class PipelineRunner:
"'": "'",
}
def flush_word():
def flush_word(force: bool = False):
nonlocal buf
if buf:
if buf or force:
tokens.append(Token(TokenKind.WORD, buf))
buf = ""
@ -178,6 +178,7 @@ class PipelineRunner:
escape = True
elif c == quote:
quote = None
flush_word(force=True) # 引号闭合时强制 flush即使是空字符串
else:
buf += c
i += 1
@ -188,7 +189,7 @@ class PipelineRunner:
i += 1
continue
if c.isspace() or c in "":
if c.isspace() or c in " ":
flush_word()
i += 1
continue

View File

@ -205,3 +205,21 @@ async def test_while_body_can_use_if(runner: PipelineRunner):
assert not isinstance(parsed, str)
results = await runner.run_pipeline(parsed, None, TextHandlerEnvironment(False))
assert results[0].code == 1
@pytest.mark.asyncio
async def test_echo_empty_string(runner: PipelineRunner):
"""测试 echo 空字符串"""
# 双引号空字符串
parsed = runner.parse_pipeline('echo ""')
assert not isinstance(parsed, str)
results = await runner.run_pipeline(parsed, None, TextHandlerEnvironment(False))
assert results[0].code == 0
assert results[0].ostream == ''
# 单引号空字符串
parsed2 = runner.parse_pipeline("echo ''")
assert not isinstance(parsed2, str)
results2 = await runner.run_pipeline(parsed2, None, TextHandlerEnvironment(False))
assert results2[0].code == 0
assert results2[0].ostream == ''