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:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user