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()