Skip to content

fix dictionary keys with dots#61

Open
meop wants to merge 1 commit intoSamboyCoding:masterfrom
meop:fix_dictionary_keys_with_dots
Open

fix dictionary keys with dots#61
meop wants to merge 1 commit intoSamboyCoding:masterfrom
meop:fix_dictionary_keys_with_dots

Conversation

@meop
Copy link

@meop meop commented Jan 22, 2026

The original code in WriteValueToStringBuilder called GetValue(subKey) to re-fetch the value. But GetValue uses TomlKeyUtils.GetTopLevelAndSubKeys which interprets periods as nested table separators. This meant dictionary keys like "key.with.dots" would fail because it tried to find a subtable instead of a flat key.

The workaround (commit 75d5c8f): The author added . to the valid bare key characters as a quick fix. But this was incorrect per the TOML spec and just happened to work because keys with periods wouldn't get quoted, then the code would "find" them via the dotted key logic.

The proper fix:

  1. Pass value directly - Since we're iterating over Entries, the value is already available. No need to call GetValue(subKey) which interprets dots.
  2. Don't escape keyName - keyName is the hierarchical path (like Planets.Inhabitants) built up through recursion. Each component was already escaped when it was added as a subKey. Escaping the whole path was wrong.
  3. Remove period from IsValidKey - Per TOML spec, bare keys can only contain A-Za-z0-9_-. Periods are separators, not valid bare key characters. Dictionary keys containing periods must be quoted.

Why underscore and dash are still valid: The TOML spec explicitly allows them in bare keys: "Bare keys may only contain ASCII letters, ASCII digits, underscores, and dashes (A-Za-z0-9_-)."

@meop
Copy link
Author

meop commented Jan 22, 2026

I guess the README's "A word on dotted keys" may need updating, if you merge this update.

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