Skip to content

Resolve %(section.key)s references - #442

Open
unknwon wants to merge 1 commit into
mainfrom
section-key-references
Open

unknwon wants to merge 1 commit into
mainfrom
section-key-references

Conversation

@unknwon

@unknwon unknwon commented Nov 15, 2026

Copy link
Copy Markdown
Member

Describe the pull request

%(name)s could only refer to a key of the same section or of the default section. A reference can now name a key in any section as %(section.key)s:

[db]
host = localhost
port = 5432

[app]
dsn = %(db.host)s:%(db.port)s

Lookup order, so existing files keep their meaning:

  1. A key named name in the reference's own section, then in the default section, as before. A key whose name contains a dot, such as db.host = x, still wins.
  2. Otherwise the name is split at the last dot into section and key, so %(db.replica.port)s reads port in the child section [db.replica].
  3. If neither matches, or the match is the key itself, the reference is left as written, as before.

The existing limits on depth, substitution count and expanded length apply, so %(x.a)s ↔ %(y.b)s cycles stop.

Link to the issue: closes #286

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code.

AI usage

Written by Amp (an AI coding agent) at the maintainer's request. Validation: go test ./..., go vet, 20 s of FuzzWriteRoundTrip, and a scratch check with CaseInsensitive. The new test covers child sections, dotted key names taking precedence in the own and default sections, missing keys, a self-reference and a cross-section cycle. The reference cases fail on main.

A reference names a key of its own section or of the default section,
as before. When neither has the name, it's split at the last dot into a
section and a key, so %(db.port)s reads port in [db] (#286).

This branch has not been deployed

No deployments
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.

Support for %(<section>.<key>) Recursive Values

1 participant