This commit is contained in:
2026-06-07 22:51:21 +08:00
parent 6b88cb1015
commit 5fd346bb65

View File

@@ -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
""",