Skip to content

Normalize default section names in case-insensitive files - #445

Open
FFspiky wants to merge 1 commit into
go-ini:mainfrom
FFspiky:fix/normalize-default-section-names
Open

FFspiky wants to merge 1 commit into
go-ini:mainfrom
FFspiky:fix/normalize-default-section-names

Conversation

@FFspiky

@FFspiky FFspiky commented Nov 17, 2026

Copy link
Copy Markdown

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

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.

1 participant