Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions goconfigobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ func (co *ConfigObj) multiLineValue(value string, lines []string, curIndex, maxL
}

func (co *ConfigObj) matchParentSectDepth(sect *Section, depth int) *Section {
for {
if sect == nil || sect == sect.Parent() {
return nil
}
if sect == nil || sect == sect.Parent() {
return nil
}

sect := sect.Parent()
if sect.Depth() == depth {
return sect.Parent()
}
section := sect.Parent()
if section.Depth() == depth {
return section.Parent()
}

return co.matchParentSectDepth(section, depth)
}

//Section get section, if not have section, return nil
Expand Down
24 changes: 24 additions & 0 deletions goconfigobj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ func TestSectionDepth(t *testing.T) {
}
}

func TestSectionMultiDepth(t *testing.T) {
txt := `
aa = bb

[fff]
bb =gg
[[zz]]
[[["ggg"]]]
aa =aa

[eee]
bb =gg
[[zz]]
[[["ggg"]]]
aa =aa
`
co := NewConfigObj(strings.NewReader(txt))
if co.Value("aa") == "bb" && co.Section("fff").Section("zz").Section("ggg").Value("aa") == "aa" && co.Section("fff").Value("bb") == "gg" && co.Section("eee").Section("zz").Section("ggg").Value("aa") == "aa" && co.Section("eee").Value("bb") == "gg" {
t.Log("SectionMultiDepth test ok")
} else {
t.Error("SectionMultiDepth test failed")
}
}

func TestChinese(t *testing.T) {
txt := `
[fff]
Expand Down