Skip to content

Merge [DEFAULT] into the default section when case-insensitive - #445

Merged
unknwon merged 2 commits into
go-ini:mainfrom
FFspiky:fix/normalize-default-section-names
Nov 17, 2026
Merged

unknwon merged 2 commits into
go-ini:mainfrom
FFspiky:fix/normalize-default-section-names

Conversation

@FFspiky

@FFspiky FFspiky commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Describe the pull request

With CaseInsensitive(true) or CaseInsensitiveSections(true), loading before=1\n[DEFAULT]\nafter=2\n creates separate default and DEFAULT sections. Normal lookup only finds the first, so Section("").Key("after") reads as missing. Explicit NewSection(DefaultSection) and recreating a deleted default section through Section(DefaultSection) have the same naming mismatch.

Lowercase the configured default name in addSection and missingSection, just as parsing the implicit default section, lookups and deletion already do. This keeps explicit default headers and writes reachable through both the configured name and "". The regression tests cover both insensitive options, custom default names, parsing and write/reload, new and missing sections, non-unique sections, and case-sensitive/key-only controls.

Link to the issue: #198 (current-v2 reproduction).

All 16 new insensitive leaf cases fail on b9a42897a3d258c3c2a207f53bd13756f687dfdd and pass with the fix; the compatibility controls pass before and after. On macOS arm64 with Go 1.27.4, full go test ./... -race -cover -shuffle=on -count=1 passes (95.4% coverage), as do go vet ./..., go build ./..., golangci-lint 2.15.0, gofmt and git diff --check. Other Go versions and operating systems were not tested locally.

There is a shared addSection hunk with #444: its new storedSectionName helper currently preserves the same default-name exception. This PR fixes existing behavior independently of the new copy/rename APIs, and also covers missingSection.

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

OpenAI Codex investigated the issue and contribution requirements, wrote the reproduction comment, implemented and reviewed the patch and tests, ran the validation above, and drafted this PR description.

@FFspiky
FFspiky requested a review from unknwon as a code owner November 17, 2026 02:16
@FFspiky

FFspiky commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

The Go workflow is waiting for approval to run. Could a maintainer approve it when convenient? Local Go 1.27.4 race/coverage tests and golangci-lint 2.15.0 pass; the upstream Go/OS matrix is still unverified.

addSection now lowercases the default section name in case-insensitive
files, so the lexer no longer needs to, and no section is stored under the
configured name in a different case.

@unknwon unknwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@unknwon unknwon changed the title Normalize default section names in case-insensitive files Merge an explicit [DEFAULT] header into the default section in case-insensitive files Nov 17, 2026
@unknwon unknwon changed the title Merge an explicit [DEFAULT] header into the default section in case-insensitive files Merge [DEFAULT] into the default section when case-insensitive Nov 17, 2026
@unknwon
unknwon merged commit 8c187cf into go-ini:main Nov 17, 2026
7 checks passed
@unknwon

unknwon commented Nov 17, 2026

Copy link
Copy Markdown
Member

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.

2 participants