fix: support empty string literals in textfx

- Fix tokenizer to emit empty string token when closing quote on empty buffer
- Add force parameter to flush_word() to handle empty quoted strings
- Add test case for echo "" and echo ''
This commit is contained in:
2026-03-18 19:23:42 +08:00
parent bfb8ebab29
commit 9bac2b8cdf
2 changed files with 22 additions and 3 deletions

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