Skip to content

Fix TOML encoder to quote keys containing special characters#2648

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-special-characters-in-toml
Draft

Fix TOML encoder to quote keys containing special characters#2648
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-special-characters-in-toml

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

TOML bare keys are restricted to [A-Za-z0-9_-]. The encoder was emitting keys like http://sealos.hub:5000 or /tmp/blah unquoted, producing invalid TOML that failed to re-parse.

Changes

  • encoder_toml.go: Added two helpers:
    • tomlKey(key) — returns key unchanged if it's a valid bare key, otherwise wraps it with %q
    • tomlDottedKey(path) — joins path segments for table/array-of-tables headers, quoting each segment as needed
  • Applied these helpers across all key-emission sites: scalar attributes, array attributes, inline table keys, [[array-of-tables]] headers, and [table] section headers

Example

Before (invalid TOML):

host = { http://sealos.hub:5000 = { capabilities = ["pull", "resolve", "push"], skip_verify = true } }

After (valid, re-parseable TOML):

host = { "http://sealos.hub:5000" = { capabilities = ["pull", "resolve", "push"], skip_verify = true } }

Copilot AI changed the title [WIP] Fix parsing failure for toml files with special characters Fix TOML encoder to quote keys containing special characters Apr 6, 2026
Copilot AI requested a review from mikefarah April 6, 2026 09:44
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.

转换为toml文件时如果key包含特殊字符会由于没有加引号导致二次解析失败

2 participants