From 5fd346bb6570fa59f581014aca2f4ebdccfa3a05 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sun, 7 Jun 2026 22:51:21 +0800 Subject: [PATCH] fix bug --- KAGParser.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/KAGParser.py b/KAGParser.py index f1334a5..9829cbe 100644 --- a/KAGParser.py +++ b/KAGParser.py @@ -78,8 +78,9 @@ class TagNode(INode): parts.append(key) else: val_str = str(value) - # Quote the value if it contains spaces to ensure it's parsed correctly. - if " " in val_str or "=" in val_str: + # Quote the value if it contains spaces (ASCII or full-width) + # to ensure it's parsed correctly on round-trip. + if " " in val_str or "\u3000" in val_str or "=" in val_str: parts.append(f'{key}="{val_str}"') else: parts.append(f"{key}={val_str}") @@ -134,6 +135,9 @@ class KAGScriptParser: # Regex to parse attributes within a tag/command string. # It handles: key=value, key="value", key='value', and boolean keys. + # Note: Only ASCII whitespace (space, tab) is treated as an attribute + # separator. Unicode whitespace such as U+3000 (full-width space) is + # preserved as part of an unquoted value. _ATTR_RE = re.compile( r""" ([a-zA-Z0-9_]+) # Attribute key @@ -142,7 +146,7 @@ class KAGScriptParser: ( "[^"]*" | # Double-quoted value '[^']*' | # Single-quoted value - [^\s\]]+ # Unquoted value + [^ \t\]]+ # Unquoted value (no ASCII space, tab, or ']') ) )? # The entire value part is optional """,