From 4da291ccf3c2907b5bcaeaf01b89006b88263f37 Mon Sep 17 00:00:00 2001 From: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> Date: Sun, 18 Oct 2026 21:34:20 +0300 Subject: [PATCH] parser: mark empty unparseable sections as raw --- parser.go | 2 +- section_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/parser.go b/parser.go index 513b19e..a2e6fd4 100644 --- a/parser.go +++ b/parser.go @@ -461,6 +461,7 @@ func (f *File) parse(reader io.Reader) (err error) { if f.options.UnparseableSections[i] == name || ((f.options.Insensitive || f.options.InsensitiveSections) && strings.EqualFold(f.options.UnparseableSections[i], name)) { inUnparseableSection = true + section.isRawSection = true continue } } @@ -468,7 +469,6 @@ func (f *File) parse(reader io.Reader) (err error) { } if inUnparseableSection { - section.isRawSection = true section.rawBody += string(line) continue } diff --git a/section_test.go b/section_test.go index 09ed366..2126886 100644 --- a/section_test.go +++ b/section_test.go @@ -21,6 +21,18 @@ import ( "github.com/stretchr/testify/require" ) +func TestEmptyUnparseableSection(t *testing.T) { + for _, input := range []string{"[raw]", "[raw]\n", "[raw]\n[next]\nkey=value"} { + t.Run(input, func(t *testing.T) { + f, err := LoadSources(LoadOptions{UnparseableSections: []string{"raw"}}, []byte(input)) + require.NoError(t, err) + sec := f.Section("raw") + sec.SetBody("raw content") + assert.Equal(t, "raw content", sec.Body()) + }) + } +} + func TestSection_SetBody(t *testing.T) { t.Run("set body of raw section", func(t *testing.T) { f := Empty()