Skip to content

Fix parsing of last {...} section in *.items files to allow inner curly braces inside quoted values#74

Open
mannemiethe wants to merge 3 commits intomaxbec:masterfrom
mannemiethe:master
Open

Fix parsing of last {...} section in *.items files to allow inner curly braces inside quoted values#74
mannemiethe wants to merge 3 commits intomaxbec:masterfrom
mannemiethe:master

Conversation

@mannemiethe
Copy link
Copy Markdown

@mannemiethe mannemiethe commented Jan 13, 2026

Hey Max, would be nice if you merge this:

Problem
*.items files were getting corrupted when the final {...} block contained nested curly braces in quotes (e.g., JSON-like metadata). The previous regex patterns assumed no additional braces inside this block, causing parsing errors and invalid file output.

Cause
The old regex for the last {...} section was too restrictive:

const REGEX_ITEM_CHANNEL_START = /\{\s*(\w*\s?=\s?"(?:[^"\\]|\\.)*"?,?\s*)+\}?/;
const REGEX_ITEM_CHANNEL_END = /.*[\},]/;
const REGEX_ITEM_CHANNEL_SECTION = /(\w+\=\"(?:[^"\\]|\\.)*\"\s*(\[.*?\])?)+/g;

These patterns failed when braces appeared inside quoted strings.

Solution
Replaced the regex with more permissive patterns that:
Capture the entire trailing {...} block.
Allow curly braces only inside quoted values (unquoted braces remain invalid).
Preserve optional [tags] syntax.

const REGEX_ITEM_CHANNEL_START = /\{.*\}$/;
const REGEX_ITEM_CHANNEL_END = /.*\}$/;
const REGEX_ITEM_CHANNEL_SECTION = /\w+="[^"]*"(\s*\[[^\]]*\])?/g;

Example (now supported):
String ColorLightOffice_name "Color Light Office" <colorlight> (ColorLightOffice) ["Control"] { initializeDefaultState="{'de_name': 'Farb Licht', 'en_name': 'Color Light', 'location2': {'name': 'Color Light', 'location': 'Office'}}" }
ItemsCurlyBraces
Impact:

✅ Fixes corruption when inner braces appear inside quoted values.
✅ Maintains compatibility with existing item definitions.
⚠️ Inner braces outside quotes remain invalid (by design).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant